setAll method Null safety
- @override
- int index,
- Iterable<
E> iterable
Overwrites elements with the objects of iterable.
The elements of iterable are written into this list,
starting at position index.
var list = ['a', 'b', 'c', 'd'];
list.setAll(1, ['bee', 'sea']);
list.join(', '); // 'a, bee, sea, d'
This operation does not increase the length of the list.
The index must be non-negative and no greater than length.
The iterable must not have more elements than what can fit from index
to length.
If iterable is based on this list, its values may change during the
setAll operation.
Implementation
@override
void setAll(int index, Iterable<E> iterable) {
RangeError.checkValidRange(index, index + iterable.length, length, "index",
"index + iterable.length");
// Listen to the element that will be added
for (E element in iterable) {
if (_propagateNotification &&
element != null &&
element is ChangeNotifier) {
element.addListener(_propagate);
}
}
// Stop listening to the element that will be replaced
for (int i = index; i < index + iterable.length; i++) {
E element = elementAt(i);
if (_propagateNotification &&
element != null &&
element is ChangeNotifier) {
element.addListener(_propagate);
}
}
_values.setAll(index, iterable);
notifyListeners();
}