chunk function

List chunk(
  1. List array,
  2. dynamic size
)

Creates an array of elements split into groups the length of size. If array can't be split evenly, the final chunk will be the remaining elements.

Implementation

List chunk(List array, size) {
  return array.isEmpty
      ? array
      : ([
          array.take(size).toList(),
          ...chunk(array.skip(size).toList(), size).toList()
        ]);
}