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");
    return await manager().write(
      key: key,
      value: jsonEncode(object),
    );
  } on Exception catch (e) {
    NyLogger.error(e.toString());
    NyLogger.error(
        '[NyStorage.saveJson] Failed to save $object to local storage. Please ensure that the object is a valid JSON object.');
  }
}