Created
September 30, 2020 20:47
-
-
Save csells/9d0fed8833c2e94e9a66d7fa466f6b36 to your computer and use it in GitHub Desktop.
flutter-state-restoration
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
| class CounterState extends State<RestorableCounter> with RestorationMixin { | |
| @override | |
| String get restorationId => widget.restorationId; | |
| RestorableInt _counter = RestorableInt(0); | |
| @override | |
| void restoreState(RestorationBucket oldBucket) => registerForRestoration(_counter, 'count'); | |
| void _incrementCounter() => setState(() => _counter.value++); | |
| @override | |
| Widget build(BuildContext context) => Scaffold( | |
| body: Center(child: Text('${_counter.value}')), | |
| floatingActionButton: FloatingActionButton(onPressed: _incrementCounter), | |
| ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment