Skip to content

Instantly share code, notes, and snippets.

@csells
Created September 30, 2020 20:47
Show Gist options
  • Select an option

  • Save csells/9d0fed8833c2e94e9a66d7fa466f6b36 to your computer and use it in GitHub Desktop.

Select an option

Save csells/9d0fed8833c2e94e9a66d7fa466f6b36 to your computer and use it in GitHub Desktop.
flutter-state-restoration
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