PrefItem<T> class

Represents a particular named value in a PrefsStorage.

The value property acts like a synchronous "cache", while real reading and writing is done asynchronously in background.

For a newly created object the value always returns null, since the data is not read yet.

Inheritance
Implemented types
Implementers

Constructors

PrefItem(PrefsStorage storage, String key, {T initFunc()?, CheckValueFunc<T?>? checkValue})

Properties

checkValue CheckValueFunc<T?>?
An optional callback that will be called before changing the value or saving a new value to the storage.
final
hashCode int
The hash code for this object.
no setterinherited
hasListeners bool
Whether any listeners are currently registered.
no setterinherited
initialized Future<PrefItem<T>>
Future completes when the object initialization completes. That means we have read value or NULL from the storage.
no setter
initializedValue Future<T?>
Allows to wait when for the first value being asynchronously read after object creation.
no setter
isDisposed bool
Returns true after dispose was called.
no setter
isInitialized bool
no setter
key String
The current item key (or name, or id - depending on the storage).
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
storage PrefsStorage
The parent storage containing the current item.
final
value ↔ T?
The current value stored in this notifier.
getter/setter pairoverride

Methods

addListener(VoidCallback listener) → void
Register a closure to be called when the object changes.
inherited
adjust(AdjustFunc f) Future<T?>
Reads an existing value, computes a new one with AdjustFunc and writes the new value to the storage.
defined() Future<bool>
Returns TRUE if we have the value in storage, otherwise FALSE.
dispose() → void
Discards any resources used by the object. After this is called, the object is not in a usable state and should be discarded (calls to addListener will throw after the object is disposed).
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyListeners() → void
Call all the registered listeners.
inherited
read() Future<T?>
Reads and returns the data from storage. value property will also be updated.
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that are notified when the object changes.
inherited
toString() String
A string representation of this object.
inherited
toWaitList(List<Future> list) → void
write(T? value) Future<void>

Operators

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