splitByLength method

List<List<int>> splitByLength(
  1. int length, {
  2. bool ignoreEmpty = false,
})

Implementation

List<List<int>> splitByLength(int length, {bool ignoreEmpty = false}) {
  List<List<int>> pieces = [];

  for (int i = 0; i < this.length; i += length) {
    int offset = i + length;

    List<int> piece = sublist(i, offset >= this.length ? this.length : offset);

    pieces.add(piece);
  }
  return pieces;
}