load<T> static method
- String key, [
- T? defaultValue
Loads a value of type T
from local storage.
Returns the stored value for the key
, or the defaultValue
if the key
is not found, or if the data is corrupted/cannot be cast to type T
.
Implementation
static T? load<T>(String key, [T? defaultValue]) {
final prefixedKey = _keyPrefix + key;
final storedValue = window.localStorage.getItem(prefixedKey);
if (storedValue == null) {
return defaultValue;
}
try {
return json.decode(storedValue) as T;
} catch (e) {
warn('LocalStorage Warning: Failed to load/decode key "$key". Returning default value. Error:', e);
return defaultValue;
}
}