Created
February 27, 2020 12:23
-
-
Save mubasshir/6f3981dfa0c186cb9dcf2fac4c8622ef to your computer and use it in GitHub Desktop.
Dart Array Pagination
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() { | |
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