Signal<T> class
A base-class that store a value of T
and notify the listeners
when the value is updated.
You can create a new Signal:
// usign `.signal` extension
final strSignal = "initial value".signal;
final intSignal = 0.signal;
final userSignal = User().signal;
// or usign the constructor class
final strSignal = Signal<String>("initial value");
final intSignal = Signal<int>(0);
final userSignal = Signal<User>(User());
You can get the value:
// usign a `value` getter
print(strSignal.value);
// or using the callable
print(strSignal());
// or using `toString` implicit
print("$intSignal");
You can set a new value:
// usign a `value` setter
strSignal.value = "change value";
// or using the callable
strSignal("change value");
You can use Lifecycle.willUpdate
event for before the value is changed,
or use Lifecicle.didUpdate
event for after the value is changed:
Reactter.on(
strSignal,
Lifecycle.willUpdate,
(signal, _) => print("Previous value: $signal"),
);
Reactter.on(
strSignal,
Lifecycle.didUpdate,
(signal, _) => print("Current value: $signal"),
);
Use update
method to notify changes after run a set of instructions:
userSignal.update((user) {
user.firstname = "Leo";
user.lastname = "Leon";
});
Use refresh
method to force to notify changes.
userSignal.refresh();
If you use flutter, add flutter_reactter
package on your dependencies and use its Widgets.
See also:
- Obj, a base-class that can be used to store a value of
T
.
- Inheritance
- Mixed-in types
- Available extensions
- ObjBigIntExt
- ObjBigIntNullExt
- ObjBoolExt
- ObjDateTimeExt
- ObjDateTimeNullExt
- ObjDoubleExt
- ObjDoubleNullExt
- ObjIntExt
- ObjIntNullExt
- ObjIterableExt
- ObjIterableNullExt
- ObjListExt
- ObjListNullExt
- ObjMapExt
- ObjMapNullExt
- ObjNullExt
- ObjNumExt
- ObjNumNullExt
- ObjSetExt
- ObjSetNullExt
- ObjStringExt
- ObjStringNullExt
- ObjToSignalExt
- SignalListExt
- SignalListNullExt
- SignalMapExt
- SignalMapNullExt
- SignalNullExt
- SignalSetExt
- SignalSetNullExt
- SignalToObjExt
Constructors
- Signal(T initial)
Properties
Methods
-
call(
[T? val]) → T -
Gets and/or sets to value like a function
This method doesn't allow setting its value to null.
If you need to set null as value, use
.value = null
.override -
dispose(
) → void -
Called when this object is removed
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
refresh(
) → void -
Forces update and notifies to listeners that it did update
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
update(
covariant void fnUpdate(T value)) → void -
Executes
fnUpdate
, and notify the listeners about to update.override -
updateAsync(
covariant void fnUpdate(dynamic value)) → Future< void> -
Executes
fnUpdate
, and notify the listeners about to update as async way.override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited