read method
Get the persisted state
Implementation
Object? read() {
setPersistStateSingleton();
if (persistStateProvider != null && !_isInitialized) {
_isInitialized = true;
return _persistStateSingleton!.init().then(
(_) => () => read(),
);
}
try {
final Object? r = cachedJson ?? _persistStateSingleton!.read(key);
if (r == null) {
return null;
}
if (r is Future) {
return r.then(
(dynamic value) {
cachedJson = value as String?;
return () => _fromJsonHandler(
key,
cachedJson,
);
},
);
}
cachedJson = r as String?;
return _fromJsonHandler(key, cachedJson);
} catch (e, s) {
if (catchPersistError) {
StatesRebuilerLogger.log('Read form localStorage error', e, s);
return null;
} else if (debugPrintOperations) {
StatesRebuilerLogger.log(
'PersistState: Read Error ($key) :$e',
);
}
rethrow;
}
}