lesnitsky / flutter_localstorage

📦 LocalStorage for Flutter
MIT License
301 stars 60 forks source link

NoSuchMethodError when call _flush() #14

Closed KorionCN closed 5 years ago

KorionCN commented 5 years ago

when I call setItem to save my Json, throw NoSuchMethodError in _flush(), because _file is null. so, I modified my code like:

local_storage.ready.then((_){
     local_storage.setItem();
})

It work normal, but finally I modified source code instead:

Future<void> _flush() async {
    final serialized = json.encode(_data);
    try {
      await ready;  //just add this line
      await _file.writeAsString(serialized);
     ...
   }

I think it is more reasonable to do so.