add method
Adds value
to this Watcher's value.
Returns true
if value
(or an equal value) was not yet in this Watcher's value.
Otherwise returns false
and this Watcher's value is not changed.
Example:
final dateTimesWatcher = <DateTime>{}.watcher;
final time1 = DateTime.fromMillisecondsSinceEpoch(0);
final time2 = DateTime.fromMillisecondsSinceEpoch(0);
// time1 and time2 are equal, but not identical.
assert(time1 == time2);
assert(!identical(time1, time2));
final time1Added = dateTimes.add(time1);
print(time1Added); // true
// A value equal to time2 exists already in this [Watcher]'s value, and the call to
// add doesn't change this [Watcher]'s value.
final time2Added = dateTimes.add(time2);
print(time2Added); // false
print(dateTimes); // {1970-01-01 02:00:00.000}
assert(dateTimes.length == 1);
assert(identical(time1, dateTimes.first));
print(dateTimes.length);
Implementation
@override
bool add(E value) => updateOnAction(() => this.value.add(value));