stack_wallet/lib/utilities/extensions/impl/list.dart

20 lines
409 B
Dart
Raw Normal View History

2024-05-30 18:46:41 +00:00
extension ListExt<T> on List<T> {
List<List<T>> chunked({required int chunkSize}) {
final remainder = length % chunkSize;
final count = length ~/ chunkSize;
final List<List<T>> result = [];
int i = 0;
while (i < count) {
result.add(sublist(i, i + chunkSize));
i++;
}
if (remainder > 0) {
result.add(sublist(i, i + remainder));
}
return result;
}
}