restoreObjects static method

Future<void> restoreObjects(
  1. String key,
  2. void callback(
    1. void update<T>(
      1. T t
      ),
    2. String modelName,
    3. String jsonStr
    )
)

Deserializes the previously serialized string into an object and

  • updates WrenchStore
  • updates Persistence store

Implementation

static Future<void> restoreObjects(
  String key,
  void Function(
    void Function<T>(T t) update,
    String modelName,
    String jsonStr,
  ) callback,
) async {
  LazyBox lazyBox = Hive.lazyBox(cacheName);
  if (lazyBox.isOpen) {
    Map<String, String> cacheData =
        (await lazyBox.get(key))?.cast<String, String>() ?? {};
    for (String modelKey in cacheData.keys) {
      WrenchStore.persistObject(modelKey, cacheData[modelKey]!);
      callback(WrenchStore.update, modelKey, cacheData[modelKey]!);
    }
  }
}