diff --git a/lib/models/auth.dart b/lib/models/auth.dart index 8d1ce3ef..0d92289e 100644 --- a/lib/models/auth.dart +++ b/lib/models/auth.dart @@ -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, ); } @@ -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, ); } @@ -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, ); } @@ -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, @@ -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, ); diff --git a/lib/screens/bb_user.dart b/lib/screens/bb_user.dart index d0197a2e..b40a640b 100644 --- a/lib/screens/bb_user.dart +++ b/lib/screens/bb_user.dart @@ -34,10 +34,7 @@ class BbUserScreen extends StatelessWidget { ]); return Tuple2( BbUser.fromJson(res[0]), - [ - for (var v in (res[1] as BbPagePayload).data) - BbRepo.fromJson(v) - ], + [for (var v in res[1].data) BbRepo.fromJson(v)], ); }, action: isViewer diff --git a/lib/screens/gl_project.dart b/lib/screens/gl_project.dart index 43a52d31..317cb803 100644 --- a/lib/screens/gl_project.dart +++ b/lib/screens/gl_project.dart @@ -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 { diff --git a/lib/utils/utils.dart b/lib/utils/utils.dart index 1cfd7cd6..0c287c1c 100644 --- a/lib/utils/utils.dart +++ b/lib/utils/utils.dart @@ -189,3 +189,5 @@ int sortByKey(T key, T a, T b) { if (a != key && b == key) return 1; return 0; } + +const TOTAL_COUNT_FALLBACK = 999; // TODO: