ComputedAsync<T> class
============================================================================ COMPUTED ASYNC (DERIVED ASYNC SIGNALS)
Computed signal that handles async operations.
ComputedAsync automatically recomputes when dependencies change and manages loading/error states.
Example:
class UserController extends NeuronController {
late final userId = Signal<int>(1).bind(this);
late final user = ComputedAsync<User>(
() => api.getUser(userId.val),
[userId],
).bind(this);
}
// In UI
AsyncSlot<User>(
connect: controller.user,
onData: (ctx, user) => Text(user.name),
)
- Inheritance
-
- Object
- NeuronAtom<
AsyncState< T> > - AsyncSignal<
T> - ComputedAsync
Constructors
-
ComputedAsync(Future<
T> _compute(), List<Listenable> _dependencies, {String? debugLabel})
Properties
- canRefresh → bool
-
Whether a refresh operation is possible.
no setterinherited
- data → T?
-
Current data (null if loading or error).
no setterinherited
- debugLabel → String?
-
Debug label for identification in DevTools.
finalinherited
-
equals
→ bool Function(AsyncState<
T> a, AsyncState<T> b)? -
Custom equality function to determine if value has changed.
finalinherited
- error → Object?
-
Current error (null if loading or has data).
no setterinherited
-
guard
→ AsyncState<
T> Function(AsyncState<T> current, AsyncState<T> next)? -
Value guard/transformer called before setting a new value.
finalinherited
- hasData → bool
-
Whether has data.
no setterinherited
- hasError → bool
-
Whether has error.
no setterinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasListeners → bool
-
Whether this atom has any listeners.
no setterinherited
-
initialValue
→ AsyncState<
T> -
The initial value of the atom.
no setterinherited
- isDisposed → bool
-
Whether this atom has been disposed.
no setterinherited
- isLoading → bool
-
Whether currently loading.
no setterinherited
- onCancel → VoidCallback?
-
Callback invoked when the last listener unsubscribes.
finalinherited
- onListen → VoidCallback?
-
Callback invoked when the first listener subscribes.
finalinherited
-
previousValue
→ AsyncState<
T> ? -
The previous value of the atom (before the last change).
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
state
→ AsyncState<
T> -
The current async state.
no setterinherited
-
value
↔ AsyncState<
T> -
The current value of the atom.
getter/setter pairinherited
Methods
-
addListener(
VoidCallback listener) → void -
Adds a listener to be called when the value changes.
inherited
-
dispose(
) → void -
Disposes the atom, removing all listeners.
override
-
emitData(
T data) → void -
Set data state.
inherited
-
emitError(
Object err, [StackTrace? stackTrace]) → void -
Set error state.
inherited
-
emitLoading(
) → void -
Set loading state.
inherited
-
execute(
Future< T> operation()) → Future<void> -
Execute an async operation and handle states automatically.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notifyListeners(
) → void -
Manually notifies all listeners.
inherited
-
onActive(
) → void -
Called when the first listener is added.
inherited
-
onInactive(
) → void -
Called when the last listener is removed.
inherited
-
refresh(
) → Future< void> -
Re-execute the last operation.
inherited
-
removeListener(
VoidCallback listener) → void -
Removes a previously added listener.
inherited
-
reset(
) → void -
Resets the atom to its initial value.
inherited
-
select<
R> (R selector(AsyncState< T> value)) → NeuronAtom<R> -
Creates a new atom that selects a part of this atom's value.
inherited
-
subscribe(
VoidCallback listener) → VoidCallback -
Adds a listener and returns a callback that cancels the subscription when called.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited