Cretezy / redux_persist

Persist Redux State
https://pub.dartlang.org/packages/redux_persist
MIT License
130 stars 41 forks source link

Example code leads to Exception #59

Closed Tobi696 closed 4 years ago

Tobi696 commented 4 years ago

The example code in the readme leads to following Error:

StorageException (StorageException: On load: ServicesBinding.defaultBinaryMessenger was accessed before the binding was initialized.
If you're running an application and need to access the binary messenger before `runApp()` has been called (for example, during plugin initialization), then you need to explicitly call the `WidgetsFlutterBinding.ensureInitialized()` first.
If you're running a test, you can call the `TestWidgetsFlutterBinding.ensureInitialized()` as the first line in your test's `main()` method to initialize the binding.)

It can be fixed by calling WidgetsFlutterBinding.ensureInitialized(); before calling persistor.load, but this makes the app startup slowly.

Please help!

Cretezy commented 4 years ago

This seems like an upstream from the storage engine. If you are calling load before runApp is ran, this is expected. I'll add a note in the README.

ensureInitialized is the same as doing runApp though, so no change is startup speed is expected. It's

Cretezy commented 4 years ago

Let me know if you have any follow up questions!

ghost23 commented 4 years ago

Hi @Cretezy , how would you change the code in your Example then, to make it work?

https://github.com/Cretezy/redux_persist/blob/master/packages/redux_persist_flutter/example/redux_persist_flutter_example.dart#L16

I am struggling to find a solution.