restoreCachedStateSync method

  1. @protected
void restoreCachedStateSync()

Tries to restore cached state

If cached state is empty does nothing if cached state is not empty calls onRestore

Implementation

@protected
void restoreCachedStateSync() {
  if (!stateFulInstanceSettings.isRestores) {
    return;
  }

  final stateFromCacheJsonString = KoreApp.cacheGetDelegate(
    stateFulInstanceSettings.stateId,
  );

  if (stateFromCacheJsonString == null || stateFromCacheJsonString.isEmpty) {
    return;
  }

  try {
    final restoredMap = json.decode(stateFromCacheJsonString);
    onRestore(restoredMap);
  } catch (_) {
    // ignore
  }
}