Cretezy / redux_persist

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

Flutter example doesn't work? #69

Closed wujek-srujek closed 3 years ago

wujek-srujek commented 3 years ago

It seems the example here: https://github.com/Cretezy/redux_persist/blob/master/packages/redux_persist_flutter/example/redux_persist_flutter_example.dart doesn't work. First, it requires the WidgetsFlutterBinding.ensureInitialized(); call because otherwise it fails with:

Unhandled Exception: 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.

When the line is added, it fails with:

Unhandled Exception: SerializationException: On load: NoSuchMethodError: The method '[]' was called on null.
Receiver: null
Tried calling: []("counter")

That's because this function: https://github.com/Cretezy/redux_persist/blob/master/packages/redux_persist_flutter/example/redux_persist_flutter_example.dart#L38 doesn't handle null, which is the initial value the first time the application is ever launched.

callagga commented 3 years ago

had same issue

DmitriyGribennikov commented 3 years ago

It seems the example here: https://github.com/Cretezy/redux_persist/blob/master/packages/redux_persist_flutter/example/redux_persist_flutter_example.dart doesn't work. First, it requires the WidgetsFlutterBinding.ensureInitialized(); call because otherwise it fails with:

Unhandled Exception: 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.

When the line is added, it fails with:

Unhandled Exception: SerializationException: On load: NoSuchMethodError: The method '[]' was called on null.
Receiver: null
Tried calling: []("counter")

That's because this function: https://github.com/Cretezy/redux_persist/blob/master/packages/redux_persist_flutter/example/redux_persist_flutter_example.dart#L38 doesn't handle null, which is the initial value the first time the application is ever launched. Same issue. Have you found solution?

wujek-srujek commented 3 years ago

@DmitriyGribennikov yes, just add WidgetsFlutterBinding.ensureInitialized(); somewhere before your code using this library if you don't have it yet for the first issue. Add a null check for the second issue.

But personally I've migrated away from this library as it seems pretty abandoned, the last commit on master is 6 months old, and nobody answers to issues at all. (Actually, I've migrated away from Redux in general, not a big fan.)

daniel-sc commented 3 years ago

This should be added to the readme/example on https://pub.dev/packages/redux_persist !