Created
July 26, 2022 20:48
-
-
Save iapicca/c6b0defa700f8003103c51fb120b74f6 to your computer and use it in GitHub Desktop.
pagination example
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
| List<int> intUntil(int n) => [for (var i = 0; i < n; ++i) i]; | |
| extension PaginateX<T> on List<T> { | |
| Iterable<Iterable<T>> paginateBy(int n) sync* { | |
| final floor = (length / n).floor(); | |
| for (var i = 0; i < floor; ++i) { | |
| yield getRange(i * n, (i + 1) * n); | |
| } | |
| final rem = length % n; | |
| if (rem > 0) { | |
| yield getRange(length - rem, length); | |
| } | |
| } | |
| } | |
| void main() { | |
| for (final list in intUntil(100).paginateBy(11)) { | |
| print(list); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment