getRange method
Creates an Iterable that iterates over a range of elements.
The returned iterable iterates over the elements of this list with positions greater than or equal to start
and less than end
.
The provided range, start
and end
, must be valid at the time of the call. A range from start
to end
is valid if 0 ≤ start
≤ end
≤ length. An empty range (with end == start
) is valid.
The returned Iterable behaves like skip(start).take(end - start)
. That is, it does not break if this list changes size, it just ends early if it reaches the end of the list early (if end
, or even start
, becomes greater than length).
List<String> colors = ['red', 'green', 'blue', 'orange', 'pink']; Iterable<String> range = colors.getRange(1, 4); range.join(', '); // 'green, blue, orange' colors.length = 3; range.join(', '); // 'green, blue'
Implementation
Iterable<E> getRange(int start, int end);
© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dart.dev/stable/2.13.0/dart-core/List/getRange.html