splitByLength method

List<List<T>> splitByLength(
  1. int length
)

Cut the original list into one or more lists with at most length items.

Implementation

List<List<T>> splitByLength(int length) {
  assert(length > 0);
  List<List<T>> chunks = <List<T>>[];
  for (var i = 0; i < this.length; i += length) {
    var end = (i + length < this.length) ? i + length : this.length;
    chunks.add(sublist(i, end));
  }
  return chunks;
}