Cretezy / redux_persist

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

Supporting asynchronous methods #42

Closed jlcool closed 5 years ago

jlcool commented 5 years ago

AppState.fromJson is an asynchronous method,I can't write it like this. How should I write it?

    var p= Persistor<AppState>(
      storage: FlutterStorage(),
      serializer:  JsonSerializer((j) async {
        return await AppState.fromJson(j);
      }
    ),
    ) ;
Cretezy commented 5 years ago

How come is it asynchronous? Since it's just serializing, it should be synchronous, and you must do any async actions after loading (such as after doing persistor.load(), which will return the result of the serializer)

jlcool commented 5 years ago

Because I encrypt and decrypt the serialized data, and this encryption and decryption method is asynchronous, I am afraid that the serialized data will be modified, affecting software security.

Cretezy commented 5 years ago

That's supposed to be part of the storage instead. Copy/paste the FlutterStorage and add your encryption there

jlcool commented 5 years ago

Well, thank you

Cretezy commented 5 years ago

No problem! Let me know if you need any help. Feel free to create a package to let others use it too!