Signal<T> class

A Signal holds a single reactive value of type T.

When its value is read, it automatically registers the currently active consumer as an observer. When its value changes, it notifies all observers.

Supports automatic lifecycle management via autoDispose and lifecycle callbacks onListen and onDispose.

Implementers
Available extensions

Constructors

Signal(T _value, {String? name, bool autoDispose = false, void onDispose()?, void onListen()?})
Creates a new Signal with the given initial value and optional lifecycle callbacks.

Properties

autoDisposeEnabled bool
Whether this signal should automatically dispose of its resources when it has no observers.
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
isDisposed bool
Tracks whether the signal is currently in a disposed state.
getter/setter pair
name String?
Optional name for debugging and observation.
final
observers Set<Consumer>
The set of active consumers currently observing this node.
finalinherited
onDisposeCallback ↔ void Function()?
Callback executed when this signal is disposed (e.g. observers drop to 0 under autoDispose).
getter/setter pair
onListenCallback ↔ void Function()?
Callback executed when this signal is first observed or revived after auto-disposal.
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
value ↔ T
Gets the current value of the signal.
getter/setter pair

Methods

addChangeListener(void listener(T previous, T current)) → void
Registers a lightweight value-change callback that does not count as a reactive observer for auto-disposal.
addObserver(Consumer consumer) → void
Registers a consumer to observe changes on this node.
autoDispose({void onDispose()?}) Signal<T>
Configures this signal to automatically dispose when all observers are removed, returning the signal itself to allow fluent builder chaining.
dispose() → void
Disposes of the resources associated with this signal, executing the onDisposeCallback.
hydrate({required String key, required T fromJson(String value), required String toJson(T value), SignalStorage? storage}) Signal<T>

Available on Signal<T>, provided by the HydratedSignalExtension extension

Hydrates (persists) the current signal using the provided storage or globalSignalStorage.
listen(void listener(T previous, T current), {bool fireImmediately = false}) SignalSubscription<T>
Listens to value changes without creating an Effect manually.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyObservers() → void
Notifies all registered observers that the value of this node has changed.
inherited
peek() → T
Returns the current value without registering a reactive dependency.
removeChangeListener(void listener(T previous, T current)) → void
Removes a callback previously registered with addChangeListener.
removeObserver(Consumer consumer) → void
Unregisters a consumer from observing this node.
setValueSilently(T newValue) → void
Sets the value of this signal without notifying its observers.
toString() String
A string representation of this object.
override
watch(BuildContext context) → T

Available on Signal<T>, provided by the SignalFlutterExtension extension

Subscribes the current BuildContext (widget) to this signal.

Operators

operator ==(Object other) bool
The equality operator.
inherited