Created
July 14, 2021 00:43
-
-
Save isaacadariku/ee5b830ebc490b0d8c61531f617283b9 to your computer and use it in GitHub Desktop.
A gist to separate list into chucks of list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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