Skip to content

Instantly share code, notes, and snippets.

@rodydavis
Created December 18, 2024 08:20
Show Gist options
  • Save rodydavis/3a15eff374f6af86816189952aacd021 to your computer and use it in GitHub Desktop.
Save rodydavis/3a15eff374f6af86816189952aacd021 to your computer and use it in GitHub Desktop.
Signals functional widgets
// ignore_for_file: non_constant_identifier_names
import 'package:flutter/material.dart';
import 'package:signals/signals_flutter.dart';
void main() {
runApp(MaterialApp(
debugShowCheckedModeBanner: false,
home: Counter(),
));
}
Widget Counter() {
final counter = signal(0);
return Scaffold(
appBar: AppBar(
title: const Text('Example'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text('You have pushed the button this many times:'),
Watch((context) {
return Text(
'$counter',
style: Theme.of(context).textTheme.headlineMedium,
);
}),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () => counter.value++,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment