slice method
Returns a new list containing elements at indices between start
(inclusive) and end
(inclusive).
If end
is omitted, it is being set to lastIndex
.
Implementation
List<E> slice(int start, [int end = -1]) {
final list = this is List ? this as List<E> : toList();
var _start = start;
var _end = end;
if (_start < 0) {
_start = _start + list.length;
}
if (_end < 0) {
_end = _end + list.length;
}
RangeError.checkValidRange(_start, _end, list.length);
return list.sublist(_start, _end + 1);
}