chunk method

List<List<T>> chunk(
  1. int n
)

Split the list into chunks of size n. Returns a list of chunks.

Implementation

List<List<T>> chunk(int n) {
  final chunks = <List<T>>[];
  for (var i = 0; i < length; i += n) {
    chunks.add(sublist(i, i + n));
  }
  return chunks;
}