load<T> static method

T? load<T>(
  1. String key, [
  2. T? defaultValue
])

Loads a value of type T from storage.

Returns the stored value, or defaultValue if the key is not found or the data cannot be decoded.

Implementation

static T? load<T>(String key, [T? defaultValue]) {
  final stored = _backend?.load(key);
  if (stored == null) return defaultValue;
  try {
    return json.decode(stored) as T;
  } catch (e) {
    warn('LocalStorage Warning: Failed to decode key "$key". Returning default.', e);
    return defaultValue;
  }
}