ULocalStorage class abstract
Fast key/value storage on all 6 platforms; tokens are encrypted automatically (Keychain/Keystore-backed key; web: sealed in IndexedDB). ULocalStorage.set("name", "Sina"); ULocalStorage.getString("name")
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
-
changes
→ Stream<
UStorageChange> -
Every change in normal storage.
no setter
- isEmpty → bool
-
True when nothing is saved.
no setter
- length → int
-
Number of saved keys.
no setter
-
secureChanges
→ Stream<
UStorageChange> -
Every change in encrypted storage.
no setter
Static Methods
-
clear(
) → Future< void> -
Deletes everything, tokens included (logout).
await ULocalStorage.clear() -
clearSecure(
) → Future< void> - Deletes every encrypted value.
-
containsKey(
String key) → bool -
True when
keyis saved and not expired. -
containsSecure(
String key) → bool -
True when
keyis saved encrypted. -
deleteStore(
String name, {bool secure = false}) → Future< void> -
Deletes a separate store and all its data.
ULocalStorage.deleteStore("cache") -
expire(
String key, Duration? expireTime) → Future< void> -
Sets (or with null removes) the expiry of a saved key.
ULocalStorage.expire("otp", 2.minutes) -
flush(
) → Future< void> - Writes pending changes to disk now (they are written automatically too).
-
get<
T> (String key) → T? -
Reads a value as any type, incl. DateTime, Duration, Uint8List.
ULocalStorage.get<DateTime>("lastSync") -
getAll(
) → Map< String, dynamic> - Every key and value (for debugging).
-
getBool(
String key) → bool? - Reads a bool.
-
getBytes(
String key) → Uint8List? - Reads bytes saved with set().
-
getDateTime(
String key) → DateTime? - Reads a DateTime saved with set().
-
getDouble(
String key) → double? - Reads a double.
-
getDuration(
String key) → Duration? - Reads a Duration saved with set().
-
getEnum<
T extends Enum> (String key, List< T> values) → T? -
Reads an enum saved with set().
ULocalStorage.getEnum("theme", ThemeMode.values) -
getInt(
String key) → int? -
Reads an int.
ULocalStorage.getInt("count") -
getKeys(
) → Set< String> - Every saved key (normal and encrypted).
-
getList(
String key) → List? - Reads a JSON list.
-
getLocale(
) → String? - Reads the saved app language code.
-
getMap(
String key) → Map< String, dynamic> ? - Reads a JSON map.
-
getObject<
T> (String key, T fromJson(Map< String, dynamic> json)) → T? -
Reads a model saved with set() (anything with toJson), via its fromJson.
ULocalStorage.getObject("user", UUserResponse.fromJson) -
getObjects<
T> (String key, T fromJson(Map< String, dynamic> json)) → List<T> ? -
Reads a list of models, via fromJson.
ULocalStorage.getObjects("addresses", Address.fromJson) -
getOr<
T> (String key, T fallback) → T -
Reads a value, or
fallbackwhen missing.ULocalStorage.getOr<int>("volume", 50) -
getRefreshToken(
) → String? - Reads the refresh token.
-
getRefreshTokenExpiresAt(
) → DateTime? - Reads when the refresh token expires.
-
getSecure<
T> (String key) → T? -
Reads an encrypted value.
ULocalStorage.getSecure<String>("pin") -
getString(
String key, {(String, String)? encryptKeyIv}) → String? -
Reads a String; pass the same
encryptKeyIvused in set() to decrypt.ULocalStorage.getString("name") -
getStringList(
String key) → List< String> ? - Reads a list of strings.
-
getToken(
) → String? - Reads the auth token (null when logged out).
-
getUserId(
) → String? - Reads the saved user id.
-
hasToken(
) → bool -
True when an auth token is saved (logged in).
home: ULocalStorage.hasToken() ? HomePage() : LoginPage() -
increment(
String key, {int by = 1}) → int -
Adds
byto a saved int and returns the new value.ULocalStorage.increment("opens") -
init(
) → Future< void> - Loads storage from disk; initU() already does it.
-
isDarkMode(
) → bool - Reads the saved dark mode choice (false when never set).
-
listenable<
T> (String key) → ValueListenable< T?> -
Value of
keyfor ValueListenableBuilder (rebuilds when it changes).ValueListenableBuilder(valueListenable: ULocalStorage.listenable<int>("cartCount"), builder: (c, n, _) => Text("${n ?? 0}")) -
openStore(
String name, {bool secure = false}) → Future< UStore> -
Opens a separate storage file you can clear on its own;
secureencrypts it.final UStore cache = await ULocalStorage.openStore("cache"); -
remove(
String key) → Future< void> -
Deletes
key.await ULocalStorage.remove("cart") -
removeAll(
Iterable< String> keys) → Future<void> - Deletes several keys.
-
removeSecure(
String key) → Future< void> - Deletes an encrypted value.
-
removeWhere(
bool test(String key, Object value)) → Future< void> -
Deletes every key that matches
test.ULocalStorage.removeWhere((k, v) => k.startsWith("cache_")) -
set(
String key, dynamic value, {Duration? expireTime, (String, String)? encryptKeyIv}) → void -
Saves any JSON-able value (null deletes);
expireTimeauto-deletes;encryptKeyIvAES-encrypts a String.ULocalStorage.set("cart", items, expireTime: 1.days) -
setAll(
Map< String, Object?> entries, {Duration? expireTime}) → Future<void> -
Saves many values and waits until they are on disk.
await ULocalStorage.setAll({"a": 1, "b": 2}) -
setAndWait(
String key, Object? value, {Duration? expireTime}) → Future< void> -
Like set() but waits until the value is on disk (before exit/logout).
await ULocalStorage.setAndWait("done", true) -
setDarkMode(
bool isDarkMode) → void - Saves the dark mode choice.
-
setLocale(
String value) → void -
Saves the app language code.
ULocalStorage.setLocale("fa") -
setRefreshToken(
String value) → void - Saves the refresh token (encrypted).
-
setRefreshTokenExpiresAt(
DateTime? value) → void - Saves when the refresh token expires (null deletes it).
-
setSecure(
String key, Object? value, {Duration? expireTime}) → Future< void> -
Saves a value encrypted.
await ULocalStorage.setSecure("pin", "1234") -
setToken(
String value, {Duration? expireTime}) → void -
Saves the auth token (encrypted); UHttpClient sends it automatically.
ULocalStorage.setToken(response.token) -
setUserId(
String userId) → void - Saves the user id.
-
store(
String name) → UStore -
A store already opened with openStore().
ULocalStorage.store("cache").set("k", v) -
ttlOf(
String key) → Duration? -
Time left before
keyexpires; null when it never expires. -
update<
T> (String key, T? transform(T? current)) → Future< void> -
Changes a value based on its current value.
ULocalStorage.update<int>("score", (v) => (v ?? 0) + 10) -
watch<
T> (String key, {bool emitCurrent = true}) → Stream< T?> -
Emits the value of
keynow and on every change.ULocalStorage.watch<int>("cartCount").listen(updateBadge)