I've seen PageStorage in the documentation. From what I understand its almost like a sharedpreference alternative from the Android world.
How do I use it, and why does it need a Widget in it's implementation?
Below simple example:
home.dart
final pageStorageBucket = PageStorageBucket();
@override
Widget build(BuildContext context) {
return PageStorage(
bucket: pageStorageBuket,
child: Scaffold(
...
),
);
}
child.dart
int storedValue;
@override initState() {
super.initState();
storedValue = PageStorage.of(context).readState(context, identifier: 'value');
}
void storeValue(int value) {
PageStorage.of(context).writeState(context, value, identifier: 'value');
}
PageStorage is for tracking the state of widgets that may not always be instantiated, for example the position of parallel list views in a pageable view (like when when you have several tabs each with its own list). For something like sharedpreference, you should probably use sharedpreference itself (via a plugin). See also https://github.com/flutter/flutter/issues/4757 or https://github.com/flutter/flutter/issues/3427.
I'm not sure what PageStorage the class is for, but based on your notes, it sounds like you're looking for key value storage.
There is a bug on file about providing a nice plugin for such: https://github.com/flutter/flutter/issues/4757
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With