Skip to content

Commit

Permalink
fix: pagination null
Browse files Browse the repository at this point in the history
  • Loading branch information
pd4d10 committed May 30, 2021
1 parent 9b3a6fc commit 87dbe87
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
20 changes: 12 additions & 8 deletions lib/models/auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,16 @@ class AuthModel with ChangeNotifier {
final res = await http.get(Uri.parse('${activeAccount!.domain}/api/v4$p'),
headers: {'Private-Token': token});
final next = int.tryParse(
res.headers['X-Next-Pages'] ?? res.headers['x-next-page'] ?? '')!;
res.headers['X-Next-Pages'] ?? res.headers['x-next-page'] ?? '');
final info = json.decode(utf8.decode(res.bodyBytes));
if (info is Map && info['message'] != null) throw info['message'];
return DataWithPage(
data: info,
cursor: next,
cursor: next ?? 1,
hasMore: next != null,
total:
int.tryParse(res.headers['X-Total'] ?? res.headers['x-total'] ?? '')!,
total: int.tryParse(
res.headers['X-Total'] ?? res.headers['x-total'] ?? '') ??
TOTAL_COUNT_FALLBACK,
);
}

Expand Down Expand Up @@ -318,7 +319,8 @@ class AuthModel with ChangeNotifier {
data: info,
cursor: page + 1,
hasMore: info is List && info.length > 0,
total: int.tryParse(res.headers['x-total-count'] ?? '')!,
total: int.tryParse(res.headers['x-total-count'] ?? '') ??
TOTAL_COUNT_FALLBACK,
);
}

Expand Down Expand Up @@ -421,7 +423,8 @@ class AuthModel with ChangeNotifier {
data: info,
cursor: page + 1,
hasMore: info is List && info.length > 0,
total: int.tryParse(res.headers['x-total-count'] ?? '')!,
total: int.tryParse(res.headers['x-total-count'] ?? '') ??
TOTAL_COUNT_FALLBACK,
);
}

Expand Down Expand Up @@ -504,7 +507,8 @@ class AuthModel with ChangeNotifier {
final info = json.decode(utf8.decode(res.bodyBytes));

final totalPage = int.tryParse(res.headers['total_page'] ?? '');
final totalCount = int.tryParse(res.headers['total_count'] ?? '')!;
final totalCount =
int.tryParse(res.headers['total_count'] ?? '') ?? TOTAL_COUNT_FALLBACK;

return DataWithPage(
data: info,
Expand Down Expand Up @@ -584,7 +588,7 @@ class AuthModel with ChangeNotifier {
final v = BbPagination.fromJson(data);
return BbPagePayload(
cursor: v.next,
total: v.size!,
total: v.size ?? TOTAL_COUNT_FALLBACK,
data: v.values,
hasMore: v.next != null,
);
Expand Down
5 changes: 1 addition & 4 deletions lib/screens/bb_user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ class BbUserScreen extends StatelessWidget {
]);
return Tuple2(
BbUser.fromJson(res[0]),
[
for (var v in (res[1] as BbPagePayload<List>).data)
BbRepo.fromJson(v)
],
[for (var v in res[1].data) BbRepo.fromJson(v)],
);
},
action: isViewer
Expand Down
3 changes: 2 additions & 1 deletion lib/screens/gl_project.dart
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ class GlProjectScreen extends StatelessWidget {
leftIconData: Octicons.git_branch,
text: Text(AppLocalizations.of(context)!.branches),
rightWidget: Text(
(branch == null ? p.defaultBranch : branch)! +
((branch == null ? p.defaultBranch : branch) ??
'' /** empty project */) +
' • ' +
branches.length.toString()),
onTap: () async {
Expand Down
2 changes: 2 additions & 0 deletions lib/utils/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,5 @@ int sortByKey<T>(T key, T a, T b) {
if (a != key && b == key) return 1;
return 0;
}

const TOTAL_COUNT_FALLBACK = 999; // TODO:

0 comments on commit 87dbe87

Please sign in to comment.