Created
December 18, 2024 08:20
-
-
Save rodydavis/3a15eff374f6af86816189952aacd021 to your computer and use it in GitHub Desktop.
Signals functional widgets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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