value property
Returns the current value and establishes a reactive dependency.
When accessed within a reactive context (like a Computed or Effect), the context will be notified when this signal changes.
Example:
final counter = Signal(0);
final doubled = Computed(() => counter.value * 2); // Creates dependency
Implementation
@override
T get value {
// Trigger lazy initialization
if (!_isInitialized) {
_loadSync();
}
return super.value;
}
Sets a new value for the signal and notifies subscribers when it changes.
Parameters:
- value: The new value to set
Example:
final counter = Signal(0);
counter.value = 10;
counter.set(11);
Sets a new value for the signal and notifies subscribers when it changes.
Parameters:
- value: The new value to set
Example:
final counter = Signal(0);
counter.value = 10;
counter.set(11);
Implementation
@override
set value(T newValue) {
if (!_isInitialized) {
_loadSync();
}
super.value = newValue;
_version++;
_scheduleWrite(newValue);
}