Reactive<T> class
A generic reactive variable that automatically notifies listeners when its value changes.
Reactive is the core building block of the reactiv state management system. It wraps any value and provides reactive capabilities including:
- Automatic notification of value changes
- Listener management with named callbacks
- Stream binding for reactive data flows
- Debounce and throttle for performance optimization
- Undo/redo functionality with history tracking
- Integration with Flutter's Observer widgets
Example:
// Create a reactive variable
final counter = Reactive<int>(0);
// Listen to changes
counter.addListener((value) => print('Counter: $value'));
// Update the value
counter.value = 1; // Prints: Counter: 1
// Use with Observer widget
Observer(
builder: (context) => Text('${counter.value}'),
);
For nullable types, use ReactiveN instead.
Constructors
Properties
- canRedo → bool
-
Returns
trueif redo is available.no setter - canUndo → bool
-
Returns
trueif undo is available.no setter - hashCode → int
-
The hash code for this object.
no setterinherited
-
listeners
→ List<
Function> -
Returns a list of all registered listener functions.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- value ↔ T
-
Gets the current value of the reactive variable.
getter/setter pair
-
valueNotifier
→ ValueNotifier<
T> -
Provides access to the underlying ValueNotifier.
no setter
Methods
-
addListener(
void listener(T value), {String? listenerName}) → void -
Registers a
listenerthat will be called whenever the value changes. -
bindStream(
Stream< T> stream) → StreamSubscription<T> -
Binds a
streamto this reactive variable. -
clearHistory(
) → void - Clears all history and resets to the current value.
-
close(
) → void - Disposes of all resources used by this reactive variable.
-
ever(
void callback(T value)) → void -
Registers a
callbackthat executes every time the value changes. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
once(
void callback(T value)) → void -
Registers a
callbackthat executes only once on the next value change. -
redo(
) → bool - Reapplies a previously undone value.
-
refresh(
) → void - Manually triggers an update to all listeners and Observer widgets.
-
removeAllListeners(
) → void - Removes all registered listeners from this reactive variable.
-
removeListener(
{required String listenerName}) → void -
Removes a specific listener by its
listenerName. -
setDebounce(
Duration duration) → void - Configures debounce behavior for value updates.
-
setThrottle(
Duration duration) → void - Configures throttle behavior for value updates.
-
toString(
) → String -
A string representation of this object.
inherited
-
undo(
) → bool - Reverts to the previous value in history.
-
updateDebounced(
T value) → void - Updates the value with debounce applied.
-
updateThrottled(
T value) → void - Updates the value with throttle applied.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited