add method Null safety
- @override
- E element
Adds value
to the set.
Returns true
if value
(or an equal value) was not yet in the set.
Otherwise returns false
and the set is not changed.
Example:
var set = Set();
var time1 = DateTime.fromMillisecondsSinceEpoch(0);
var time2 = DateTime.fromMillisecondsSinceEpoch(0);
// time1 and time2 are equal, but not identical.
assert(time1 == time2);
assert(!identical(time1, time2));
set.add(time1); // => true.
// A value equal to time2 exists already in the set, and the call to
// add doesn't change the set.
set.add(time2); // => false.
assert(set.length == 1);
assert(identical(time1, set.first));
Implementation
@override
bool add(E element) {
bool result = _values.add(element);
if (result) {
// Listen to the element if asked to and if it is possible
if (_propagateNotification &&
element != null &&
element is ChangeNotifier) {
element.addListener(_propagate);
}
notifyListeners();
}
return result;
}