diff --git a/lib/screens/gitlab_project.dart b/lib/screens/gitlab_project.dart index 5333f82..e77ea29 100644 --- a/lib/screens/gitlab_project.dart +++ b/lib/screens/gitlab_project.dart @@ -41,8 +41,7 @@ class GitlabProjectScreen extends StatelessWidget { return ActionButton( title: 'Project Actions', items: [ - ActionItem.share(data.webUrl), - ActionItem.launch(data.webUrl), + ...ActionItem.getUrlActions(data.webUrl), ], ); }, diff --git a/lib/screens/issue.dart b/lib/screens/issue.dart index 2f82169..9cbe319 100644 --- a/lib/screens/issue.dart +++ b/lib/screens/issue.dart @@ -401,8 +401,7 @@ mutation { }); }, ), - ActionItem.share(payload['url']), - ActionItem.launch(payload['url']), + ...ActionItem.getUrlActions(payload['url'] as String), ], ], ); diff --git a/lib/screens/repository.dart b/lib/screens/repository.dart index 13e2d8d..d78e2e3 100644 --- a/lib/screens/repository.dart +++ b/lib/screens/repository.dart @@ -130,8 +130,7 @@ class RepositoryScreen extends StatelessWidget { text: 'Releases(${repo.releases.totalCount})', url: 'https://github.com/$owner/$name/releases', ), - ActionItem.share(repo.url), - ActionItem.launch(repo.url), + ...ActionItem.getUrlActions(repo.url), ], ); }, diff --git a/lib/screens/user.dart b/lib/screens/user.dart index 57beba0..e686f1b 100644 --- a/lib/screens/user.dart +++ b/lib/screens/user.dart @@ -402,20 +402,14 @@ class UserScreen extends StatelessWidget { final user = payload as GhUserUser; return ActionButton( title: 'User Actions', - items: [ - ActionItem.share(user.url), - ActionItem.launch(user.url), - ], + items: [...ActionItem.getUrlActions(user.url)], ); case 'Organization': final organization = payload as GhUserOrganization; return ActionButton( title: 'Organization Actions', items: [ - if (payload != null) ...[ - ActionItem.share(organization.url), - ActionItem.launch(organization.url), - ], + ...ActionItem.getUrlActions(organization.url), ], ); default: diff --git a/lib/widgets/action_button.dart b/lib/widgets/action_button.dart index d227a7c..bef5aff 100644 --- a/lib/widgets/action_button.dart +++ b/lib/widgets/action_button.dart @@ -18,16 +18,22 @@ class ActionItem { this.iconData, }); - ActionItem.share(String url) - : text = 'Share', - onTap = ((_) { + static List getUrlActions(String url) { + return [ + ActionItem( + text: 'Share', + onTap: (_) { Share.share(url); - }); - ActionItem.launch(String url) - : text = 'Open in Browser', - onTap = ((_) { + }, + ), + ActionItem( + text: 'Open in Browser', + onTap: (_) { launchUrl(url); - }); + }, + ), + ]; + } } class ActionButton extends StatelessWidget {