Closed raymondurgelles closed 5 years ago
Good point, there's a missing null check in the JsonSerializer, will add!
Pushed 0.8.0-rc.1
of redux_persist with a fix for this! Let me know if that's good.
It works perfectly! thanks! thumbs up!!!!
@Cretezy Still happens to me since the data in 'state = serializer.decode(data)' is null and it sends the null to the AppState.fromJson which gets an the same exception. I'm using the 0.8.0-rc.1 of redux_persist. Please can you help?
The AppState.fromJson
must be able to handle a null state. It's by design for now, because you might want to return an empty state
Oh ok.. Ill check it out tomorrow and I'll let you know if I need anything. Thanks for the fast response! Keep up the good work! :)
Thank you, keep giving feedback, it's always helpful to have someone else's opinion! :)
Good Day!!! Thanks for a very nice plugin. I am new to mobile dev and i just recently learned about redux and persist. When I was using this plugin version 0.7.0, my code is working, when i upgraded, and followed what was written in readme, i get this error
Persistor debug: Starting load... I/flutter ( 8521): Persistor debug: Loading from storage I/flutter ( 8521): Persistor debug: Running load raw transformations I/flutter ( 8521): Persistor debug: Deserializing I/flutter ( 8521): Persistor debug: Error while loading: SerializationException: On load: NoSuchMethodError: The getter 'length' was called on null. I/flutter ( 8521): Receiver: null I/flutter ( 8521): Tried calling: length E/flutter ( 8521): [ERROR:flutter/shell/common/shell.cc(188)] Dart Error: Unhandled exception: E/flutter ( 8521): SerializationException: On load: NoSuchMethodError: The getter 'length' was called on null. E/flutter ( 8521): Receiver: null E/flutter ( 8521): Tried calling: length E/flutter ( 8521): #0 Persistor.load (package:redux_persist/src/persistor.dart:131:7) E/flutter ( 8521):
E/flutter ( 8521): #1 createStore (package:halal_traveller/store/store.dart:21:38)
E/flutter ( 8521):
E/flutter ( 8521): #2 main (package:my_app/main.dart:15:23)
E/flutter ( 8521):
E/flutter ( 8521): #3 _startIsolate. (dart:isolate/runtime/libisolate_patch.dart:289:19)
E/flutter ( 8521): #4 _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:171:12)
my code is like this. I have a state with a bool constructor isInit which tells me if the app already opened once, so
`class AppState { /// final bool isInit; /// AppState ({ /// this.isInit = false /// }); /// static AppState fromJson (dynamic map) { return AppState ( /// isInit: map["isInit"] as bool, /// ) }
Map toJson() { return { /// 'isInit': isInit, /// } } /// }`
then I have this createStore(),
`Future<Store> createStore() async {
final persistor = Persistor(
storage: FlutterStorage(),
serializer: JsonSerializer(AppState.fromJson),
debug: true,
);
final middleware = [persistor.createMiddleware()];
middleware.add(new LoggingMiddleware.printer());
var initialState = await persistor.load();
return new Store(
appReducer,
middleware: middleware,
initialState: initialState ?? AppState() );
}`
then on main() i have store = await createStore(); before runApp;
when I run the code, the error above is the result.
when i read persistor.dart, i see that the error comes from here, base from debug:
try { state = serializer.decode(data); } catch (error) { throw SerializationException('On load: ${error.toString()}'); }
i think the reason is data is null on first call since there is still no file existing.
So when I added if (data != null) before state = serializer.decode(data), the error is gone.
by the way i am using flutter.