diff --git a/lib/models/theme.dart b/lib/models/theme.dart index 765d71e..4d8cc7e 100644 --- a/lib/models/theme.dart +++ b/lib/models/theme.dart @@ -50,26 +50,36 @@ class ThemeModel with ChangeNotifier { notifyListeners(); } - void pushRoute({ - @required BuildContext context, - @required WidgetBuilder builder, + pushRoute( + BuildContext context, + WidgetBuilder builder, { bool fullscreenDialog = false, }) { switch (theme) { case AppThemeType.cupertino: - Navigator.of(context).push(CupertinoPageRoute( + return Navigator.of(context).push(CupertinoPageRoute( builder: builder, fullscreenDialog: fullscreenDialog, )); - break; default: - Navigator.of(context).push(MaterialPageRoute( + return Navigator.of(context).push(MaterialPageRoute( builder: builder, fullscreenDialog: fullscreenDialog, )); } } + pushReplacementRoute(BuildContext context, WidgetBuilder builder) { + switch (theme) { + case AppThemeType.cupertino: + return Navigator.of(context) + .pushReplacement(CupertinoPageRoute(builder: builder)); + default: + return Navigator.of(context) + .pushReplacement(MaterialPageRoute(builder: builder)); + } + } + Future showConfirm(BuildContext context, String text) { switch (theme) { case AppThemeType.cupertino: diff --git a/lib/screens/repo.dart b/lib/screens/repo.dart index 9c9959e..1d850ab 100644 --- a/lib/screens/repo.dart +++ b/lib/screens/repo.dart @@ -35,7 +35,7 @@ class RepoScreen extends StatelessWidget { get _branchQueryChunk => branch == null ? 'defaultBranchRef' : 'ref(qualifiedName: "$branch")'; - get _readmeChunk => (branch ?? 'master') + ':README.md'; + get _branchName => branch ?? 'master'; get branchInfoKey => branch == null ? 'defaultBranchRef' : 'ref'; Future queryRepo(BuildContext context) async { @@ -102,7 +102,7 @@ class RepoScreen extends StatelessWidget { name } } - object(expression: "$_readmeChunk") { + object(expression: "$_branchName:README.md") { ... on Blob { text } @@ -138,8 +138,7 @@ class RepoScreen extends StatelessWidget { break; } - Provider.of(context) - .pushRoute(context: context, builder: builder); + Provider.of(context).pushRoute(context, builder); }, ), MyAction( @@ -281,21 +280,25 @@ class RepoScreen extends StatelessWidget { TableViewItem( leftIconData: Octicons.git_branch, text: Text('Branches'), - rightWidget: Text( + rightWidget: Text(_branchName + + ' • ' + numberFormat.format(payload['refs']['totalCount'])), - // onTap: () { - // Provider.of(context).showPicker( - // context, - // PickerGroupItem( - // items: (payload['refs']['nodes'] as List).map((b) => - // PickerItem(b['name'] as String, text: b['name'])), - // onChange: (v) { - // // FIXME: - // queryRepo(context); - // }, - // ), - // ); - // }, + onTap: () async { + var result = await Provider.of(context) + .showDialogOptions( + context, + (payload['refs']['nodes'] as List) + .map((b) => DialogOption( + value: b['name'] as String, + widget: Text(b['name'] as String))) + .toList()); + + if (result != null) { + Provider.of(context).pushReplacementRoute( + context, + (_) => RepoScreen(owner, name, branch: result)); + } + }, ), TableViewItem( leftIconData: Octicons.law, diff --git a/lib/widgets/link.dart b/lib/widgets/link.dart index ce123e8..8ed8ea8 100644 --- a/lib/widgets/link.dart +++ b/lib/widgets/link.dart @@ -32,9 +32,7 @@ class Link extends StatelessWidget { } if (screenBuilder != null) { - Provider.of(context).pushRoute( - context: context, - builder: screenBuilder, + Provider.of(context).pushRoute(context, screenBuilder, fullscreenDialog: fullscreenDialog); }