Skip to content

Instantly share code, notes, and snippets.

@JavierPerezLavadie
Forked from mubasshir/paginate.dart
Created June 26, 2022 13:47
Show Gist options
  • Save JavierPerezLavadie/4024c67d88be67a30311e32bd3f88515 to your computer and use it in GitHub Desktop.
Save JavierPerezLavadie/4024c67d88be67a30311e32bd3f88515 to your computer and use it in GitHub Desktop.
Dart Array Pagination
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