UStore class

One key/value store. Obtain with UStorage.instance, UStorage.secure or UStorage.open.

Properties

changes → Stream<UStorageChange>
Every change to this store, including expiries.
no setter
hashCode → int
The hash code for this object.
no setterinherited
isEmpty → bool
no setter
isNotEmpty → bool
no setter
isSecure → bool
no setter
keys → Iterable<String>
no setter
length → int
no setter
name → String
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

clear() → Future<void>
Removes every entry except u's internal "__u." keys.
expire(String key, Duration? ttl) → Future<void>
Sets or clears the ttl of an existing entry without rewriting its value.
flush() → Future<void>
Writes pending changes now instead of at the end of the event-loop turn. Completes once everything set so far is on disk; costs nothing when there is nothing to write.
get<T>(String key) → T?
The value of key as T, or null when missing, expired or of another type. Numbers convert between int and double; JSON lists read as List<String> when asked.
getEnum<T extends Enum>(String key, List<T> values) → T?
Enums are stored by name: set("mode", ThemeMode.dark) → getEnum("mode", ThemeMode.values).
getObject<T>(String key, T fromJson(Map<String, dynamic> json)) → T?
Reads an object saved with set(key, object) (anything with toJson()).
getObjects<T>(String key, T fromJson(Map<String, dynamic> json)) → List<T>?
Reads a list of objects saved with set(key, listOfObjects).
getOr<T>(String key, T fallback) → T
has(String key) → bool
increment(String key, {int by = 1}) → int
Adds by to the int under key (missing counts as 0) and returns the new value.
listenable<T>(String key) → ValueListenable<T?>
A ValueListenable for key, ready for ValueListenableBuilder. Shared per key.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
remove(String key) → Future<void>
removeAll(Iterable<String> keys) → Future<void>
removeWhere(bool test(String key, Object value)) → Future<void>
Removes every entry for which test returns true.
set(String key, Object? value, {Duration? ttl}) → Future<void>
Stores value under key (null removes it). With ttl the entry disappears once it elapses. Takes effect immediately for readers; the future completes once it is on disk.
setAll(Map<String, Object?> entries, {Duration? ttl}) → Future<void>
Stores several entries with one disk write.
toMap() → Map<String, Object>
A snapshot of every live entry.
toString() → String
A string representation of this object.
override
ttlOf(String key) → Duration?
Time left before key expires; null when it has no ttl or does not exist.
update<T>(String key, T? transform(T? current)) → Future<void>
Replaces the value of key with update(current); returning null removes it.
watch<T>(String key, {bool emitCurrent = true}) → Stream<T?>
The value of key now (when emitCurrent) and after every change.

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

isInternalKey(String key) → bool
Keys starting with "__u." belong to u itself (launch history, …) and are left out of keys, length, toMap and clear, so clearing user data on logout never resets them.