replaceRange method
Replaces a range of elements with the elements of replacement
.
Removes the objects in the range from start
to end
, then inserts the elements of replacements
at start
.
var list = [1, 2, 3, 4, 5]; list.replaceRange(1, 4, [6, 7]); list.join(', '); // '1, 6, 7, 5'
The provided range, given by start
and end
, must be valid. A range from start
to end
is valid if 0 ≤ start
≤ end
≤ length. An empty range (with end == start
) is valid.
The operation list.replaceRange(start, end, replacements)
is roughly equivalent to:
list.removeRange(start, end); list.insertAll(start, replacements);
but may be more efficient.
The list must be growable. This method does not work on fixed-length lists, even when replacement
has the same number of elements as the replaced range. In that case use setRange instead.
Implementation
void replaceRange(int start, int end, Iterable<E> iterable) { throw new UnsupportedError("Cannot modify an immutable List."); }
© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dart.dev/stable/2.13.0/dart-html/ImmutableListMixin/replaceRange.html