store static method

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

Saves an object to local storage.

Implementation

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

  if (object is String) {
    return await StorageManager.storage.write(key: key, value: object);
  }

  if (object is int) {
    return await StorageManager.storage
        .write(key: key, value: object.toString());
  }

  if (object is double) {
    return await StorageManager.storage
        .write(key: key, value: object.toString());
  }

  if (object is Storable) {
    return await StorageManager.storage
        .write(key: key, value: jsonEncode(object.toStorage()));
  }

  return await StorageManager.storage
      .write(key: key, value: object.toString());
}