AsyncComputed<T> class

A class that computes a value asynchronously and notifies listeners when the value changes.

This class allows you to track changes in a computed value derived from asynchronous operations. It automatically updates and notifies listeners whenever the underlying asynchronous operation completes.

Example usage:

final asyncValue = AsyncComputed(() async => await fetchData(), defaultValue: 'Loading...');
Inheritance

Constructors

AsyncComputed.new(Future<T> _getValue(), {T? defaultValue, T? beforeUpdate()?, bool notifyBeforeUpdate = true, void onError(dynamic error)?, dynamic immediate = false})
Creates an instance of AsyncComputed with the given async function.

Properties

beforeUpdate → T? Function()?
A callback function executed before the async computation begins. It can return an optional value that updates _value before the async process completes.
final
hashCode int
The hash code for this object.
no setterinherited
hasListeners bool
Whether any listeners are currently registered.
no setterinherited
mounted bool
Whether the notifier is mounted.
no setterinherited
notifyBeforeUpdate bool
Determines whether listeners should be notified before the async update completes.
final
onError → void Function(dynamic error)?
A callback triggered when an error occurs during computation.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
value → T?
Returns the current computed value, ensuring the async computation starts when accessed.
no setteroverride

Methods

addListener(VoidCallback listener) → void
Adds a listener to be notified when the computed value changes.
override
dispose() → void
Disposes of the AsyncComputed instance, cancelling any ongoing computation.
override
force(T? value) → void
Forces the computed value to the given value, notifying listeners if the value changes.
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
select<U>(U getter(T? value)) Computed<U>
Creates a Computed that selects a value from the notifier.
inherited
toString() String
Returns a string representation of the AsyncComputed object.
override

Operators

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