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.


  T initialValue, {
  SignalOptions<T>? options,

initialValue is the initial value of the signal.

options are the options of the signal.

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('');

Widget build(BuildContext context) {
  return TextField(
    onChanged: text.set,
    // instead of
    // onChanged: (value) => text.value = value,

T updateValue(T Function(T value) callback)#

Calls a function with the current value and assigns the result as the new value.

For example:

final count = Signal(2);
count.updateValue((value) => value * 2);
print(count()); // prints 4

ReadSignal<T> toReadSignal()#

Converts this Signal into a ReadSignal. Use this method to make the signal read-only.