ComputedAsyncNotifier<T> class
A ChangeNotifier that computes a value from a future.
The future is computed when the value is first requested, and then re-computed whenever any of the notifiers in depends change. If beforeUpdate is provided, it is called before re-computing the value.
If the computation throws, the error is stored and the value remains null. If onError is provided, it is called with the error.
- Inheritance
-
- Object
- ChangeNotifier
- ComputedAsyncNotifier
Constructors
-
ComputedAsyncNotifier(Future<
T> compute(), {required List<ChangeNotifier> depends, void onError(dynamic error)?, T? beforeUpdate()?})
Properties
- beforeUpdate → T? Function()?
-
An optional callback to call before re-computing the value.
final
-
compute
→ Future<
T> Function() -
The future that computes the value.
final
-
depends
→ List<
ChangeNotifier> -
The notifiers that trigger a re-computation of the value when changed.
final
- error → dynamic
-
The error or null if no error has occurred.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasListeners → bool
-
Whether any listeners are currently registered.
no setterinherited
- loading → bool
-
no setter
- onError → void Function(dynamic error)?
-
An optional callback to call when an error occurs.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- value → T?
-
The value or null if it hasn't been computed yet.
no setter
Methods
-
addListener(
VoidCallback listener) → void -
Register a closure to be called when the object changes.
inherited
-
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
-
forceValue(
T value) → void - Force the value to be a specific value.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notifyListeners(
) → void -
Call all the registered listeners.
inherited
-
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.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited