saveJson static method

Future saveJson(
  1. String key,
  2. dynamic object, {
  3. bool inBackpack = false,
})

Saves a JSON object to local storage.

Implementation

static Future saveJson(String key, object, {bool inBackpack = false}) async {
  if (inBackpack == true) {
    Backpack.instance.save(key, object);
  }

  try {
    await manager().write(key: "${key}_runtime_type", value: "json");
    if (object == null && key == Nylo.authKey()) {
      return await manager().write(
          key: key,
          value: jsonEncode({
            "date": DateTime.now().toIso8601String(),
          }));
    }
    return await manager().write(key: key, value: jsonEncode(object));
  } on Exception catch (e) {
    NyLogger.error(e.toString());
    NyLogger.error(
        '[NyStorage.store] Failed to store $object to local storage. Please ensure that the object is a valid JSON object.');
  }
}