Código com erro:
Future<void> reload(I18nWebClient client) async {
String keyStorage = '${viewkey}_$language';
emit(LoadingI18NMessageState());
var ready = await storage.ready;
print('searching ${keyStorage} is $ready');
final items = storage.getItem(keyStorage);
print('LocalStorage items ${items}');
if(items!= null){
emit(LoadedI18NMessageState(I18NMessages(items)));
return;
}
client.findAll().then((messages){refreshAndSave(messages, keyStorage);});
}
refreshAndSave(Map<String, dynamic> messages, String keyStorage) {
storage.setItem(keyStorage, messages);
print('saving $keyStorage');
final state = LoadedI18NMessageState(I18NMessages(messages));
emit(state);
}
Quando vou salvar no localstorage está dando este erro:
I/flutter ( 2485): I18NMessagesCubit > Change { currentState: Instance of 'LoadingI18NMessageState', nextState: Instance of 'LoadedI18NMessageState' } E/flutter ( 2485): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: NoSuchMethodError: The method 'lock' was called on null. E/flutter ( 2485): Receiver: null E/flutter ( 2485): Tried calling: lock() E/flutter ( 2485): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:54:5) E/flutter ( 2485): #1 DirUtils.flush (package:localstorage/src/directory/io.dart:48:25) E/flutter ( 2485): #2 LocalStorage.flush (package:localstorage/localstorage.dart:102:18) E/flutter ( 2485): #3 LocalStorage.setItem (package:localstorage/localstorage.dart:85:12) E/flutter ( 2485): E/flutter ( 2485): F/crashdump32(18802): crash_dump.cpp:398] failed to get process threads: No such file or directory
Quando comento a linha abaixo o erro não ocorre.
storage.setItem(keyStorage, messages);
O projeto está no github: https://github.com/pedropefj/bytebanck_v2
Pode me ajudar?