save<T> static method

void save<T>(
  1. String key,
  2. T value
)

Saves a value to storage with the given key.

The value must be JSON-serializable. If value is null, the key is removed from storage.

Implementation

static void save<T>(String key, T value) {
  if (value == null) {
    delete(key);
    return;
  }
  try {
    _backend?.save(key, json.encode(value));
  } on JsonUnsupportedObjectError catch (e) {
    error('LocalStorage Error: Failed to save key "$key".', e);
  }
}