From 3002c0736772790d204b845e1540573764271346 Mon Sep 17 00:00:00 2001 From: Rongjian Zhang Date: Tue, 6 Oct 2020 15:39:40 +0800 Subject: [PATCH] fix(github): empty repo (no ref) closes #99 --- lib/screens/gh_repo.dart | 47 ++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/lib/screens/gh_repo.dart b/lib/screens/gh_repo.dart index aec65587..16e174af 100644 --- a/lib/screens/gh_repo.dart +++ b/lib/screens/gh_repo.dart @@ -250,16 +250,15 @@ class GhRepoScreen extends StatelessWidget { Text(numberFormat.format(repo.pullRequests.totalCount)), url: '/github/$owner/$name/pulls', ), - TableViewItem( - leftIconData: Octicons.history, - text: Text('Commits'), - rightWidget: Text((ref.target as GhRepoCommit) - .history - ?.totalCount - .toString()), - url: '/github/$owner/$name/commits', - ), if (ref != null) ...[ + TableViewItem( + leftIconData: Octicons.history, + text: Text('Commits'), + rightWidget: Text( + ((ref.target as GhRepoCommit).history?.totalCount ?? 0) + .toString()), + url: '/github/$owner/$name/commits', + ), if (repo.refs != null) TableViewItem( leftIconData: Octicons.git_branch, @@ -289,22 +288,22 @@ class GhRepoScreen extends StatelessWidget { ); }, ), + TableViewItem( + leftIconData: Octicons.organization, + text: Text('Contributors'), + rightWidget: FutureBuilder( + future: context + .read() + .ghClient + .getJSON('/repos/$owner/$name/stats/contributors') + .then((v) => v.length.toString()), + builder: (context, snapshot) { + return Text(snapshot.data ?? ''); + }, + ), + url: '/github/$owner/$name/contributors', + ) ], - TableViewItem( - leftIconData: Octicons.organization, - text: Text('Contributors'), - rightWidget: FutureBuilder( - future: context - .read() - .ghClient - .getJSON('/repos/$owner/$name/stats/contributors') - .then((v) => v.length.toString()), - builder: (context, snapshot) { - return Text(snapshot.data ?? ''); - }, - ), - url: '/github/$owner/$name/contributors', - ) ], ), FutureBuilder(