save<T> static method
- String key,
- T value
Saves a value to local storage with the given key.
The value must be JSON-serializable (e.g., int, double, String,
bool, List, Map<String, dynamic>).
If value is null, the key is removed from storage.
Throws an ArgumentError if the value is not JSON-serializable.
Implementation
static void save<T>(String key, T value) {
final prefixedKey = _keyPrefix + key;
if (value == null) {
delete(key);
return;
}
try {
final serializedValue = json.encode(value);
window.localStorage.setItem(prefixedKey, serializedValue);
} on JsonUnsupportedObjectError catch (e) {
error('LocalStorage Error: Failed to save key "$key".', e);
}
}