chunkBy method

List<List<int>> chunkBy(
  1. num value
)

Implementation

List<List<int>> chunkBy(num value) {
  List<List<int>> result = [];
  final size = this.length;
  int max = size ~/ value;
  int check = size % (value as int);
  if (check > 0) {
    max += 1;
  }
  if (size <= value) {
    result = [this];
  } else {
    for (var i = 0; i < max; i++) {
      int startIndex = value * i;
      int endIndex = value * (i + 1);
      if (endIndex > size) {
        endIndex = size;
      }
      var sub = this.sublist(startIndex, endIndex);
      print("startIndex=$startIndex || endIndex=$endIndex");
      result.add(sub);
    }
  }
  return result;
}