ResultStore<K, T> class

A ChangeNotifier that creates and caches ResultNotifiers for a given key, and optionally disposes them when they are no longer used.

Listeners are notified (notifyListeners) when any of the cached ResultNotifiers changes value. To build a Widget that responds to these changes, simply use ListenableBuilder.

Typical use cases for this class are pagination or when the result for parameterized/keyed API calls need to be cached.

Inheritance
Available Extensions

Constructors

ResultStore({required CreateResultNotifier<K, T> create, ResultNotifierOnDispose<K, T>? onDispose, bool autoDispose = true, Duration autoDisposeTimerInterval = const Duration(minutes: 1)})
Creates a ResultStore that creates ResultNotifiers using the provided create function.

Properties

autoDisposeTimer Timer?
getter/setter pair
autoDisposeTimerInterval Duration
The interval used by the auto dispose timer. Defaults to one minute.
final
create CreateResultNotifier<K, T>
Function used to create a new ResultNotifier for a specific key of type K .
final
hashCode int
The hash code for this object.
no setterinherited
hasListeners bool
Whether any listeners are currently registered.
no setterinherited
lastUpdate DateTime
no setter
length int
The current number of notifiers in the store.
no setter
onDispose ResultNotifierOnDispose<K, T>?
Optional function called whenever a ResultNotifier is disposed.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
willAutoDispose bool
Whether or not to automatically ResultNotifier.dispose ResultNotifiers when there are no listeners. If this flag is set to true, all cached ResultNotifiers will also be disposed whenever the ResultStore itself is disposed.
final

Methods

addListener(VoidCallback listener) → void
Register a closure to be called when the object changes.
override
cancel(K key, {bool always = false}) Result<T>?
Cancels any ongoing fetch operation for the ResultNotifier with the specified key.
clear({bool? disposeNotifiers}) → void
Removes all cached ResultNotifiers, and disposes them if parameter disposeNotifiers or willAutoDispose is true.
data(K key) → T
Attempts to get the current data of the ResultNotifier with the specified key.
dataOrNull(K key) → T?
Gets the data, if any, of the ResultNotifier with the specified key.
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
getNotifier(K key, {bool shouldRefresh = false, bool force = false, bool alwaysTouch = false}) ResultNotifier<T>
invalidate(K key) → void
Invalidates the ResultNotifier with the specified key.
invalidateAll() → void
Invalidates all cached ResultNotifiers.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyListeners() → void
Call all the registered listeners.
inherited
onResult(void callback(K key, Result<T> result)) VoidCallback
Registers a listener (addListener) that will be invoked with the key and result of the last modified ResultNotifier, whenever one is modified.
read(K key) Result<T>?
Attempts to find a cached ResultNotifier for the specified key, and return its ResultNotifier.value.
refresh(K key, {bool force = false, bool alwaysTouch = false}) → void
Refreshes the ResultNotifier with the specified key, if needed.
refreshAwait(K key, {bool force = false, bool alwaysTouch = false}) Future<T>
Refreshes the ResultNotifier with the specified key, if needed, and awaits the result.
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that are notified when the object changes.
override
result(K key) Result<T>
Just an alias for value.
toString() String
A string representation of this object.
inherited
touch(K key) → void
Touches the ResultNotifier with the specified key.
value(K key) Result<T>
Gets the current ResultNotifier.value, of the ResultNotifier with the specified key.

Operators

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