-
-
Notifications
You must be signed in to change notification settings - Fork 179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Interoperability with state restoration #164
Comments
For now, you can use A hook support may need some PR |
Hey @rrousselGit and @foodchaining, I've created a PR (#167) to add support for managing |
I experimented with this a bit and came up with https://github.com/knaeckeKami/state_restoration_hook |
@knaeckeKami In your example, is there any way to avoid that addPostFrameCallback in the One core problem behind this feature is, we want the initial |
Are you talking about the addPostFrameCallback in the example? This is only needed to show the Snackbar in case the state was restored, the first build would already have the correct restored state. The first build would already have the restored state, the restored state is available immediately after the |
Oh I see. Personally, I would prefer if your example could be written as: class MyHomePage extends HookWidget {
@override
Widget build(BuildContext context) {
useRestorationBucket('MyHomePage');
final counter = useRestorableInt(0, 'counter');
// show the modal like in your example
useEffect(() {
if (counter.value != 0) addPostFrameCallback(<show snackbar>);
}, [/* only do this check on initial build (*/]);
...
}); |
Yes, it's definitely verbose, it's basically a full port of the RestorationMixin API. In the Most use cases probably don't need that, so it might make sense to trim the API down. It's just a first draft of what state restoration using hooks might look like, hence the experimental status, I'm happy for feedback on what could be improved in the API. |
I'd be happy to help you iterate over the API if you want. |
Thanks! I'll work on refining this later, might take a couple of weeks though. |
Hi,
There is a state restoration facility upcoming to flutter. Will
flutter_hooks
be compatible with it?The text was updated successfully, but these errors were encountered: