Skip to content

Instantly share code, notes, and snippets.

@riscait
Last active July 15, 2021 23:53
Show Gist options
  • Save riscait/50d2a17b7212e889dbfd64a81fa31fe7 to your computer and use it in GitHub Desktop.
Save riscait/50d2a17b7212e889dbfd64a81fa31fe7 to your computer and use it in GitHub Desktop.
Chunk list by do-while
void main() {
final items = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k'];
final chunkedItems = [];
final chunkSize = 3;
var count = 0;
do {
chunkedItems.add(items.skip(count).take(chunkSize).toList());
count += chunkSize;
} while (count < items.length);
print(chunkedItems); // [[a, b, c], [d, e, f], [g, h, i], [j, k]]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment