-
-
Save JavierPerezLavadie/4024c67d88be67a30311e32bd3f88515 to your computer and use it in GitHub Desktop.
Dart Array Pagination
This file contains hidden or 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() { | |
List arr = []; | |
for (int i = 0; i < 100; i++) { | |
arr.add(i.toString()); | |
} | |
int page = 1; | |
var startIndex = -1, endIndex = -1; | |
while (arr.length > 0 && endIndex != (arr.length - 1)) { | |
startIndex = (page - 1) * 10; | |
endIndex = (page) * 10 - 1; | |
print({page, startIndex, endIndex, arr.sublist(startIndex, endIndex + 1)}); | |
page++; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment