Skip to content

Commit 87dbe87

Browse files
committed
fix: pagination null
1 parent 9b3a6fc commit 87dbe87

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

lib/models/auth.dart

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -208,15 +208,16 @@ class AuthModel with ChangeNotifier {
208208
final res = await http.get(Uri.parse('${activeAccount!.domain}/api/v4$p'),
209209
headers: {'Private-Token': token});
210210
final next = int.tryParse(
211-
res.headers['X-Next-Pages'] ?? res.headers['x-next-page'] ?? '')!;
211+
res.headers['X-Next-Pages'] ?? res.headers['x-next-page'] ?? '');
212212
final info = json.decode(utf8.decode(res.bodyBytes));
213213
if (info is Map && info['message'] != null) throw info['message'];
214214
return DataWithPage(
215215
data: info,
216-
cursor: next,
216+
cursor: next ?? 1,
217217
hasMore: next != null,
218-
total:
219-
int.tryParse(res.headers['X-Total'] ?? res.headers['x-total'] ?? '')!,
218+
total: int.tryParse(
219+
res.headers['X-Total'] ?? res.headers['x-total'] ?? '') ??
220+
TOTAL_COUNT_FALLBACK,
220221
);
221222
}
222223

@@ -318,7 +319,8 @@ class AuthModel with ChangeNotifier {
318319
data: info,
319320
cursor: page + 1,
320321
hasMore: info is List && info.length > 0,
321-
total: int.tryParse(res.headers['x-total-count'] ?? '')!,
322+
total: int.tryParse(res.headers['x-total-count'] ?? '') ??
323+
TOTAL_COUNT_FALLBACK,
322324
);
323325
}
324326

@@ -421,7 +423,8 @@ class AuthModel with ChangeNotifier {
421423
data: info,
422424
cursor: page + 1,
423425
hasMore: info is List && info.length > 0,
424-
total: int.tryParse(res.headers['x-total-count'] ?? '')!,
426+
total: int.tryParse(res.headers['x-total-count'] ?? '') ??
427+
TOTAL_COUNT_FALLBACK,
425428
);
426429
}
427430

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

506509
final totalPage = int.tryParse(res.headers['total_page'] ?? '');
507-
final totalCount = int.tryParse(res.headers['total_count'] ?? '')!;
510+
final totalCount =
511+
int.tryParse(res.headers['total_count'] ?? '') ?? TOTAL_COUNT_FALLBACK;
508512

509513
return DataWithPage(
510514
data: info,
@@ -584,7 +588,7 @@ class AuthModel with ChangeNotifier {
584588
final v = BbPagination.fromJson(data);
585589
return BbPagePayload(
586590
cursor: v.next,
587-
total: v.size!,
591+
total: v.size ?? TOTAL_COUNT_FALLBACK,
588592
data: v.values,
589593
hasMore: v.next != null,
590594
);

lib/screens/bb_user.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@ class BbUserScreen extends StatelessWidget {
3434
]);
3535
return Tuple2(
3636
BbUser.fromJson(res[0]),
37-
[
38-
for (var v in (res[1] as BbPagePayload<List>).data)
39-
BbRepo.fromJson(v)
40-
],
37+
[for (var v in res[1].data) BbRepo.fromJson(v)],
4138
);
4239
},
4340
action: isViewer

lib/screens/gl_project.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,8 @@ class GlProjectScreen extends StatelessWidget {
206206
leftIconData: Octicons.git_branch,
207207
text: Text(AppLocalizations.of(context)!.branches),
208208
rightWidget: Text(
209-
(branch == null ? p.defaultBranch : branch)! +
209+
((branch == null ? p.defaultBranch : branch) ??
210+
'' /** empty project */) +
210211
' • ' +
211212
branches.length.toString()),
212213
onTap: () async {

lib/utils/utils.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,5 @@ int sortByKey<T>(T key, T a, T b) {
189189
if (a != key && b == key) return 1;
190190
return 0;
191191
}
192+
193+
const TOTAL_COUNT_FALLBACK = 999; // TODO:

0 commit comments

Comments
 (0)