Signal API docs
Signals are the cornerstone of reactivity in solidart
.
They contain values that change over time; when you change a signal's value, it automatically updates anything that uses it.
A Signal extends a ReadSignal, so all the API of ReadSignal are available.
Constructor
Signal(
T initialValue, {
SignalOptions<T>? options,
});
initialValue
is the initial value of the signal.
options
are the options of the signal.
Signal.lazy();
Signal.lazy
is a lazy signal, it doesn't need a value at the moment of creation.
But would throw a StateError if you try to access the value before setting one.
set value(T newValue)
Sets the current signal value with newValue
.
This operation may be skipped if the value is equal to the previous one, check SignalOptions.equals and SignalOptions.comparator.
For example:
final count = Signal(0);
count.value = 1; // set the value to 1
void set(T newValue)
Equal to the value setter above. This is convenient in Flutter apps where you can write:
final text = Signal('');
@override
Widget build(BuildContext context) {
return TextField(
onChanged: text.set,
// instead of
// onChanged: (value) => text.value = value,
);
}