ignoreUpdates<U> method
Runs fn while suppressing watcher callbacks caused by its updates.
Source values still change normally, but the watcher keeps the previous visible state for the next callback. This is useful when applying internal writes that should not count as observable watcher transitions.
Example:
final signal = Signal(1);
final values = <int>[];
final watcher = Watcher(
() => signal.value,
(newValue, _) => values.add(newValue),
);
signal.value = 2; // Triggers
expect(values, equals([2]));
watcher.ignoreUpdates(() {
signal.value = 3; // Does not trigger callback
});
expect(values, equals([2]));
expect(signal.value, equals(3)); // Value still updated
signal.value = 4; // Triggers again
expect(values, equals([2, 4]));
Implementation
@override
U ignoreUpdates<U>(U Function() fn) {
return batch(() {
int prevFlags = raw.flags;
try {
return fn();
} finally {
raw.flags = prevFlags;
}
});
}