generateBuiltBook method

BuiltMap<int, BuiltList<T>> generateBuiltBook({
  1. int? valuesPerPage,
  2. int? numberOfPages,
})

Implementation

BuiltMap<int, BuiltList<T>> generateBuiltBook({int? valuesPerPage, int? numberOfPages}) {
  if (valuesPerPage == null && numberOfPages == null) {
    return BuiltMap.of({0: this as BuiltList<T>});
  }
  valuesPerPage ??= length ~/ numberOfPages!;
  var book = MapBuilder<int, BuiltList<T>>();
  int pageCount = 0;
  var list = this;
  while (list.isNotEmpty && (numberOfPages == null || pageCount < numberOfPages)) {
    book[pageCount++] = BuiltList.of(list.take(valuesPerPage));
    list = list.skip(valuesPerPage);
  }
  return book.build();
}