chunked method

List<List<T>> chunked(
  1. int size
)

Implementation

List<List<T>> chunked(int size) {
  if (size <= 0) {
    throw ArgumentError.value(size, 'size', 'Must be greater than zero.');
  }

  final source = toList();

  return [
    for (var index = 0; index < source.length; index += size)
      source.sublist(
        index,
        (index + size).clamp(0, source.length).toInt(),
      ),
  ];
}