signal<T> function

WritableSignal<T> signal<T>(
  1. T initialValue
)

Creates a writable signal with the given initial value.

Signals are the most basic reactive primitive. They hold a value and notify their dependents when that value changes.

The returned signal can be called without arguments to read its value, or with an argument to write a new value.

Example:

final count = signal(0);
print(count()); // reads: 0
count.set(5);   // writes: 5
print(count()); // reads: 5
  • Parameter initialValue: The initial value of the signal.
  • Returns: A WritableSignal that can be read and written.

Implementation

@pragma('vm:prefer-inline')
@pragma('dart2js:tryInline')
@pragma('wasm:prefer-inline')
WritableSignal<T> signal<T>(T initialValue) {
  return _SignalImpl(
    flags: ReactiveFlags.mutable,
    currentValue: initialValue,
    pendingValue: initialValue,
  );
}