Rx<T> class
A simple reactive wrapper that notifies listeners when its value changes.
This is a lightweight alternative to more complex reactive programming libraries like RxDart. It's suitable for simple state management needs within the notification wrapper package.
Example usage:
final counter = Rx<int>(0);
// Listen to changes
counter.listen((value) {
print('Counter changed to: $value');
});
// Update the value (triggers listeners)
counter.value = 1;
Constructors
- Rx(T _value)
- Creates a new reactive value with the initial value.
Properties
Methods
-
clearListeners(
) → void - Removes all listeners.
-
dispose(
) → void - Disposes of the reactive value and closes the stream.
-
listen(
void callback(T)) → VoidCallback - Adds a listener that will be called whenever the value changes.
-
listenWithPrevious(
void callback(T previous, T current)) → VoidCallback - Adds a listener that will be called with both the previous and the new value on every change.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
removeListener(
void callback(T)) → void - Removes a specific listener.
-
toString(
) → String -
Returns the current value as a string.
override
-
update(
T updater(T current)) → void - Updates the value using a function and notifies listeners if changed.
Operators
-
operator ==(
Object other) → bool -
Checks equality based on the current value.
override