Closed giorgiogross closed 6 years ago
dynamic json
can actually be anything, because your toMap/Json
function could return any dynamic
.
I think the simplest thing is to do the JSON serialization code elsewhere and then call it from the fromJson
that redux_persist accepts.
Okay thanks! So basically if I enforce my toJson to return a map (just as in your example) then fromJson will get that map as parameter during deserialization?
I just noticed there is a typo in my question: I meant to call return AppState.fromJson(json)
instead of return AppState.fromJsonWrapper(json)
Hi,
how would you integrate redux_persist with json_serializable? json_serializable requires a factory method in the AppState class as such:
As it's not possible to pass a reference to the
AppState.fromJson(....)
constructor to the Persistor.decoder field I would do something like this:Is it save to assume that the
dynamic json
will always be of typeMap<String, dynamic>
? Having a look at you code it looks like that's the case, but I'm not sure though. Do you know a way to use the factory directly?