RxComputed<T> class
A reactive computed value that automatically tracks dependencies.
RxComputed automatically re-evaluates when any of its dependent
RxState or field-level dependencies change.
Features:
- Automatic dependency tracking (state + field-level)
- Lazy recomputation on dependency change
- Read-only reactive value (cannot be set manually)
final a = RxState<int>(1);
final b = RxState<int>(2);
final sum = RxComputed<int>(() => a.value + b.value);
sum.listen((val) => print('sum = $val'));
a.value = 3; // sum = 5
- Inheritance
- Available extensions
Constructors
- RxComputed(T compute())
- Creates a computed reactive value.
Properties
- compute → T Function()
-
The computation function used to derive the value.
final
- current → T
-
Available on RxComputed<
T> , provided by the RxComputedExtensions extensionno setter - hashCode → int
-
The hash code for this object.
no setterinherited
- id → dynamic
-
Unique identifier for debugging or tracking updates in listenWithId.
finalinherited
- isEmpty → bool
-
Available on RxState<
Whether the list is empty.List< , provided by the RxListToState extensionT> >no setter - isNotEmpty → bool
-
Available on RxState<
Whether the list is not empty.List< , provided by the RxListToState extensionT> >no setter - length → int
-
Available on RxState<
The number of elements in the list.List< , provided by the RxListToState extensionT> >no setter - name → String?
-
A human-readable name, mainly used for logging and debugging output.
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- v → T
-
Available on RxComputed<
Returns the current computed value.T> , provided by the RxComputedExtensions extensionno setter - value ↔ T
-
Gets the current value and automatically triggers dependency tracking in RxStack.
getter/setter pairinherited-getteroverride-setter
Methods
-
add(
T element) → void -
Available on RxState<
Adds anList< , provided by the RxListToState extensionT> >elementto the list and triggers a refresh. -
addFieldListener(
dynamic field, void listener(dynamic)) → void -
Adds a field-level listener.
inherited
-
addListener(
void listener(dynamic)) → void -
Adds a global listener.
inherited
-
addListenerWithId(
void listener(dynamic)) → void -
Adds a listener that also receives the state id.
inherited
-
bind(
void onUpdate(T value)) → void Function() -
Binds a listener to the state.
inherited
-
contains(
T element) → bool -
Available on RxState<
Returns whether the list contains the givenList< , provided by the RxListToState extensionT> >element. -
deepEquals(
dynamic a, dynamic b) → bool -
inherited
-
dispose(
) → void -
Disposes all dependency listeners.
override
-
getItem(
dynamic field) → dynamic -
Gets a specific field or index from a collection.
inherited
-
internalUpdate(
T newValue) → void -
Internal update used by computed or framework-level mechanisms.
It updates the value and triggers global listeners if the value changes.
inherited
-
listen(
void onData(T value)) → void Function() -
Listens to value changes and immediately emits the current value.
inherited
-
listenByKey(
dynamic key, void onData(dynamic)) → void Function() -
Listens to a specific key in a Map or index in a List.
inherited
-
listenWhere(
bool test(dynamic item), void onData(dynamic)) → void Function() -
Conditional listener.
inherited
-
listenWithId(
void onData(T value, dynamic id)) → void Function() -
Listens to value changes and provides both value and state id.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notifyField(
dynamic field) → void -
Notifies all listeners registered for a specific field.
inherited
-
refresh(
) → void -
Manually triggers a refresh.
inherited
-
remove(
T element) → void -
Available on RxState<
Removes anList< , provided by the RxListToState extensionT> >elementfrom the list and triggers a refresh. -
removeFieldListener(
dynamic field, void listener(dynamic)) → void -
Removes a field-level listener.
inherited
-
removeListener(
void listener(dynamic)) → void -
Removes a global listener.
inherited
-
runAsync(
{required Future< T> asyncAction(), void onLoading(bool loading)?, void onError(Object error)?, int retryCount = 3, Duration retryDelay = const Duration(seconds: 2)}) → Future<void> -
Executes an asynchronous action with automatic retry support.
inherited
-
runAsyncWithStatus(
{required Future< T> asyncAction(), void onLoading(bool loading)?, void onError(Object error)?}) → Future<void> -
Executes an asynchronous action and updates the state.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
update(
dynamic newValue) → void -
Updates the entire state or attempts a type-conversion update.
inherited
-
updateField<
K extends Object> (K field, Object? newValue) → void -
Updates a specific key in a Map or an index in a List.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited