Skip to content

Commit 78f23ef

Browse files
committed
Allow start page, per_page, number of pages options to pagination helper
1 parent 061468c commit 78f23ef

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 8.0.0-nullsafe.2
2+
- Allow start page, per_page, number of pages options to pagination helper
3+
- Allow page options for listTags
4+
15
## 8.0.0-nullsafe.1
26
- Update to null safety
37

lib/src/common/repos_service.dart

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,13 +241,12 @@ class RepositoriesService extends Service {
241241
/// Lists the tags of the specified repository.
242242
///
243243
/// API docs: https://developer.github.com/v3/repos/#list-tags
244-
Stream<Tag> listTags(RepositorySlug slug) {
244+
Stream<Tag> listTags(RepositorySlug slug,
245+
{int page = 1, int? pages, int perPage = 30}) {
245246
ArgumentError.checkNotNull(slug);
246247
return PaginationHelper(github).objects<Map<String, dynamic>, Tag>(
247-
'GET',
248-
'/repos/${slug.fullName}/tags',
249-
(i) => Tag.fromJson(i),
250-
);
248+
'GET', '/repos/${slug.fullName}/tags', (i) => Tag.fromJson(i),
249+
pages: pages, params: {'page': page, 'per_page': perPage});
251250
}
252251

253252
/// Lists the branches of the specified repository.

lib/src/common/util/pagination.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ class PaginationHelper {
2727
} else {
2828
params = Map.from(params);
2929
}
30-
assert(!params.containsKey('page'));
30+
31+
var page = params['page'] ?? 1;
32+
params['page'] = page;
3133

3234
// ignore: literal_only_boolean_expressions
3335
while (true) {
@@ -69,9 +71,7 @@ class PaginationHelper {
6971
break;
7072
}
7173

72-
final nextUrl = Uri.parse(next);
73-
final nextPageArg = nextUrl.queryParameters['page']!;
74-
params['page'] = nextPageArg;
74+
params['page'] = ++page;
7575
}
7676
}
7777

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: github
2-
version: 8.0.0-nullsafe.1
2+
version: 8.0.0-nullsafe.2
33
description: A high-level GitHub API Client Library that uses Github's v3 API
44
homepage: https://github.com/SpinlockLabs/github.dart
55

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy