From 83c22bda9acb9f113d4e4f1829721a39d7a2e705 Mon Sep 17 00:00:00 2001 From: Rongjian Zhang Date: Sun, 10 Mar 2019 21:53:35 +0800 Subject: [PATCH] feat: add view owner action at repo screen --- lib/providers/settings.dart | 21 +++++++++++++++++++++ lib/screens/repo.dart | 24 ++++++++++++++++++++++-- lib/widgets/link.dart | 18 +++++------------- 3 files changed, 48 insertions(+), 15 deletions(-) diff --git a/lib/providers/settings.dart b/lib/providers/settings.dart index 68dde63..4759010 100644 --- a/lib/providers/settings.dart +++ b/lib/providers/settings.dart @@ -7,6 +7,7 @@ import 'package:nanoid/nanoid.dart'; import 'package:url_launcher/url_launcher.dart'; // import 'package:flutter/services.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/cupertino.dart'; import 'package:shared_preferences/shared_preferences.dart'; // import '../utils/utils.dart'; import '../utils/constants.dart'; @@ -357,6 +358,26 @@ class SettingsProviderState extends State { return true; } + void pushRoute({ + @required BuildContext context, + @required WidgetBuilder builder, + bool fullscreenDialog = false, + }) { + switch (theme) { + case ThemeMap.cupertino: + Navigator.of(context).push(CupertinoPageRoute( + builder: builder, + fullscreenDialog: fullscreenDialog, + )); + break; + default: + Navigator.of(context).push(MaterialPageRoute( + builder: builder, + fullscreenDialog: fullscreenDialog, + )); + } + } + String randomString; generateRandomString() { diff --git a/lib/screens/repo.dart b/lib/screens/repo.dart index dff2154..f9a4896 100644 --- a/lib/screens/repo.dart +++ b/lib/screens/repo.dart @@ -9,6 +9,7 @@ import '../scaffolds/refresh.dart'; import '../widgets/repo_item.dart'; import '../widgets/entry_item.dart'; import '../screens/issues.dart'; +import '../screens/user.dart'; import '../widgets/action.dart'; class RepoScreen extends StatefulWidget { @@ -22,8 +23,8 @@ class RepoScreen extends StatefulWidget { } class _RepoScreenState extends State { - get owner => widget.owner; - get name => widget.name; + String get owner => widget.owner; + String get name => widget.name; Future queryRepo(BuildContext context) async { var data = await SettingsProvider.of(context).query(''' @@ -31,6 +32,7 @@ class _RepoScreenState extends State { repository(owner: "$owner", name: "$name") { id owner { + __typename login } name @@ -89,6 +91,24 @@ class _RepoScreenState extends State { var payload = data[0]; return ActionButton(title: 'Repository Actions', actions: [ + Action( + text: 'View @$owner', + onPress: () { + WidgetBuilder builder; + + switch (payload['owner']['__typename']) { + case 'Organization': + // TODO: + break; + case 'User': + builder = (_) => UserScreen(owner); + break; + } + + SettingsProvider.of(context) + .pushRoute(context: context, builder: builder); + }, + ), Action( text: payload['viewerHasStarred'] ? 'Unstar' : 'Star', onPress: () async { diff --git a/lib/widgets/link.dart b/lib/widgets/link.dart index 45abcd5..1462f3c 100644 --- a/lib/widgets/link.dart +++ b/lib/widgets/link.dart @@ -31,19 +31,11 @@ class Link extends StatelessWidget { } if (screenBuilder != null) { - switch (theme) { - case ThemeMap.cupertino: - Navigator.of(context).push(CupertinoPageRoute( - builder: screenBuilder, - fullscreenDialog: fullscreenDialog, - )); - break; - default: - Navigator.of(context).push(MaterialPageRoute( - builder: screenBuilder, - fullscreenDialog: fullscreenDialog, - )); - } + SettingsProvider.of(context).pushRoute( + context: context, + builder: screenBuilder, + fullscreenDialog: fullscreenDialog, + ); } if (url != null) {