From 925472f151ce1ef1ab2dafb9c61b2c4ee7e36d7f Mon Sep 17 00:00:00 2001 From: Rongjian Zhang Date: Sun, 10 Feb 2019 14:26:51 +0800 Subject: [PATCH] feat: add files and commits links for repo screen --- lib/screens/repo.dart | 14 ++++++++++++++ lib/utils/constants.dart | 5 ++++- lib/widgets/entry_item.dart | 7 +++++-- lib/widgets/link.dart | 10 +++++++++- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/lib/screens/repo.dart b/lib/screens/repo.dart index f01a7d5..c3930cb 100644 --- a/lib/screens/repo.dart +++ b/lib/screens/repo.dart @@ -48,6 +48,10 @@ class _RepoScreenState extends State { pullRequests(states: OPEN) { totalCount } + url + defaultBranchRef { + name + } } } @@ -106,6 +110,16 @@ class _RepoScreenState extends State { isPullRequest: true, ), ), + EntryItem( + text: 'Files', + url: payload['url'] + '?files=1', + ), + EntryItem( + text: 'Commits', + url: payload['url'] + + '/commits/' + + payload['defaultBranchRef']['name'], + ), ], ), ), diff --git a/lib/utils/constants.dart b/lib/utils/constants.dart index d91bc26..9b7ff5c 100644 --- a/lib/utils/constants.dart +++ b/lib/utils/constants.dart @@ -1,3 +1,6 @@ -// These keys are for development +// These keys are for development, not the production keys +// You can also create OAuth App at https://github.com/settings/applications/new +// to get your own keys and replace these ones + var clientId = '9b7d1cc04a1db5710767'; var clientSecret = '710e085908dde6a8b55f7a9dc447ad5c0c5617d1'; diff --git a/lib/widgets/entry_item.dart b/lib/widgets/entry_item.dart index 7b7c06a..f39ef69 100644 --- a/lib/widgets/entry_item.dart +++ b/lib/widgets/entry_item.dart @@ -5,8 +5,9 @@ class EntryItem extends StatelessWidget { final int count; final String text; final WidgetBuilder screenBuilder; + final String url; - EntryItem({this.count, this.text, this.screenBuilder}); + EntryItem({this.count, this.text, this.screenBuilder, this.url}); @override Widget build(BuildContext context) { @@ -17,12 +18,14 @@ class EntryItem extends StatelessWidget { padding: EdgeInsets.symmetric(vertical: 10), child: Column( children: [ - Text(count.toString(), style: TextStyle(fontSize: 18)), + Text(count == null ? '' : count.toString(), + style: TextStyle(fontSize: 18)), Text(text, style: TextStyle(fontSize: 13)) ], ), ), screenBuilder: screenBuilder, + url: url, ), ); } diff --git a/lib/widgets/link.dart b/lib/widgets/link.dart index 2a0c56b..c6ec25c 100644 --- a/lib/widgets/link.dart +++ b/lib/widgets/link.dart @@ -1,9 +1,11 @@ import 'package:flutter/material.dart'; import 'package:flutter/cupertino.dart'; +import 'package:url_launcher/url_launcher.dart'; import '../providers/settings.dart'; class Link extends StatelessWidget { final Widget child; + final String url; final WidgetBuilder screenBuilder; final Function beforeRedirect; final Color bgColor; @@ -13,13 +15,15 @@ class Link extends StatelessWidget { Link({ this.child, + this.url, this.screenBuilder, this.beforeRedirect, this.bgColor, this.material = true, this.fullscreenDialog = false, this.iconButton, - }) : assert(child != null || iconButton != null); + }) : assert(child != null || iconButton != null), + assert(screenBuilder == null || url == null); void _onTap(BuildContext context, int theme) { if (beforeRedirect != null) { @@ -41,6 +45,10 @@ class Link extends StatelessWidget { )); } } + + if (url != null) { + launch(url); + } } @override