set method
Updates the signal's value by method call.
Under normal conditions, this only notifies subscribers if the new value is different from the current value.
Set force to true to bypass standard equality checks and notify downstream subscribers
unconditionally. This is useful when working with mutable collections or class instances where
properties change in-place but the object reference remains identical.
final numbers = Signal([1, 2, 3]);
numbers.value.add(4); // In-place modification
numbers.set(numbers.value, force: true); // Force notify downstream subscribers
Implementation
@override
bool set(
T val, {
/// Skip equality check and update the value
bool force = false,
}) {
if (disposed) {
throw SignalsWriteAfterDisposeError(this);
}
if (force || !isInitialized || !equalityCheck.equals(val, internalValue)) {
beforeUpdate(val);
internalSetValue(val);
return true;
}
return false;
}