Last active
September 9, 2023 14:32
-
-
Save kaboc/c9695dac00b9a3410417cecb865a707f to your computer and use it in GitHub Desktop.
Minimal counter example (with Grab)
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
| import 'package:flutter/material.dart'; | |
| import 'package:grab/grab.dart'; | |
| final counter = ValueNotifier(0); | |
| void main() => runApp(const App()); | |
| class App extends StatelessWidget { | |
| const App({super.key}); | |
| @override | |
| Widget build(BuildContext context) { | |
| return MaterialApp( | |
| home: Scaffold( | |
| body: const Center( | |
| child: _CounterText(), | |
| ), | |
| floatingActionButton: FloatingActionButton( | |
| onPressed: () => counter.value++, | |
| child: const Icon(Icons.add), | |
| ), | |
| ), | |
| ); | |
| } | |
| } | |
| class _CounterText extends StatelessWidget with Grab { | |
| const _CounterText(); | |
| @override | |
| Widget build(BuildContext context) { | |
| final count = context.grab(counter); | |
| return Text('$count'); | |
| } | |
| } |
Author
kaboc
commented
Dec 7, 2022
- Grab on pub.dev
- https://pub.dev/packages/grab
- GitHub project
- https://github.com/kaboc/grab
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment