Skip to content

Instantly share code, notes, and snippets.

@isaacadariku
Created July 14, 2021 00:43
Show Gist options
  • Save isaacadariku/ee5b830ebc490b0d8c61531f617283b9 to your computer and use it in GitHub Desktop.
Save isaacadariku/ee5b830ebc490b0d8c61531f617283b9 to your computer and use it in GitHub Desktop.
A gist to separate list into chucks of list
void main() {
// Generate List of numbers
List numbers = List<int>.generate(20, (index) => index);
int length = numbers.length;
int split = 2;
List chunks = [];
for (int i = 0; i < length; i += split) {
var end = (i + split < length) ? i + split : length;
chunks.add(numbers.sublist(i, end));
}
print(numbers);
print(chunks);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment