Skip to content

Commit a7a48d1

Browse files
committed
launch url
1 parent c1a1e9e commit a7a48d1

6 files changed

Lines changed: 45 additions & 8 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
**flutter_markdown**|**markdown解析**
7676
**json_annotation**|**json模板**
7777
**json_serializable**|**json模板**
78+
**url_launcher**|**启动外部浏览器**
7879
**iconfont**|**字库图标**
7980

8081

‎lib/common/style/GSYStyle.dart‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,12 @@ class GSYStrings {
189189
static const String nothing_now = "目前什么都没有。";
190190
static const String loading_text = "加载中···";
191191

192+
193+
static const String option_web = "浏览器打开";
194+
static const String option_copy = "复制链接";
195+
static const String option_share = "分享";
196+
static const String option_web_launcher_error = "url异常";
197+
192198
static const String login_text = "登录";
193199

194200
static const String Login_out = "退出登录";

‎lib/page/PersonPage.dart‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'package:gsy_github_app_flutter/common/dao/EventDao.dart';
66
import 'package:gsy_github_app_flutter/common/dao/ReposDao.dart';
77
import 'package:gsy_github_app_flutter/common/dao/UserDao.dart';
88
import 'package:gsy_github_app_flutter/common/model/User.dart';
9+
import 'package:gsy_github_app_flutter/common/net/Address.dart';
910
import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart';
1011
import 'package:gsy_github_app_flutter/common/utils/CommonUtils.dart';
1112
import 'package:gsy_github_app_flutter/common/utils/NavigatorUtils.dart';
@@ -44,6 +45,9 @@ class _PersonState extends GSYListState<PersonPage> {
4445

4546
User userInfo = User.empty();
4647

48+
49+
String launchUrl = "";
50+
4751
_PersonState(this.userName);
4852

4953
@override
@@ -67,6 +71,7 @@ class _PersonState extends GSYListState<PersonPage> {
6771
pullLoadWidgetControl.dataList.clear();
6872
setState(() {
6973
pullLoadWidgetControl.dataList.addAll(res.data);
74+
launchUrl = Address.hostWeb + userInfo.login;
7075
});
7176
}
7277
resolveDataResult(res);
@@ -140,7 +145,7 @@ class _PersonState extends GSYListState<PersonPage> {
140145
appBar: new AppBar(
141146
title: GSYTitleBar(
142147
(userInfo != null && userInfo.login != null) ? userInfo.login : "",
143-
rightWidget: GSYCommonOptionWidget(),
148+
rightWidget: GSYCommonOptionWidget(launchUrl),
144149
)
145150
),
146151
floatingActionButton: new FloatingActionButton(
@@ -149,7 +154,7 @@ class _PersonState extends GSYListState<PersonPage> {
149154
if (focus == '') {
150155
return;
151156
}
152-
if(userInfo.type == "Organization") {
157+
if (userInfo.type == "Organization") {
153158
Fluttertoast.showToast(msg: GSYStrings.user_focus_no_support);
154159
return;
155160
}
@@ -161,7 +166,7 @@ class _PersonState extends GSYListState<PersonPage> {
161166
}),
162167
body: GSYPullLoadWidget(
163168
pullLoadWidgetControl,
164-
(BuildContext context, int index) => _renderEventItem(index),
169+
(BuildContext context, int index) => _renderEventItem(index),
165170
handleRefresh,
166171
onLoadMore,
167172
refreshKey: refreshIndicatorKey,

‎lib/widget/GSYComonOptionWidget.dart‎

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
import 'package:flutter/material.dart';
2+
import 'package:fluttertoast/fluttertoast.dart';
23
import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart';
4+
import 'package:url_launcher/url_launcher.dart';
35

46
/**
57
* Created by guoshuyu
68
* Date: 2018-07-26
79
*/
810
class GSYCommonOptionWidget extends StatelessWidget {
911

12+
final List<GSYOptionModel> otherList;
13+
14+
final String url;
15+
16+
GSYCommonOptionWidget(this.url, {this.otherList});
17+
1018
_renderHeaderPopItem(List<GSYOptionModel> list) {
1119
return new PopupMenuButton<GSYOptionModel>(
1220
child: new Icon(GSYICons.MORE),
@@ -30,16 +38,25 @@ class GSYCommonOptionWidget extends StatelessWidget {
3038
return list;
3139
}
3240

41+
_launchURL() async {
42+
if (await canLaunch(url)) {
43+
await launch(url);
44+
} else {
45+
Fluttertoast.showToast(msg: GSYStrings.option_web_launcher_error + ": " + url);
46+
}
47+
}
48+
49+
3350
@override
3451
Widget build(BuildContext context) {
3552
List<GSYOptionModel> list = [
36-
new GSYOptionModel("浏览器打开", "浏览器打开", (model) {
37-
print("浏览器打开");
53+
new GSYOptionModel(GSYStrings.option_web, GSYStrings.option_web, (model) {
54+
_launchURL();
3855
}),
39-
new GSYOptionModel("复制链接", "复制链接", (model) {
56+
new GSYOptionModel(GSYStrings.option_copy, GSYStrings.option_copy, (model) {
4057
print("复制链接");
4158
}),
42-
new GSYOptionModel("分享", "分享", (model) {
59+
new GSYOptionModel(GSYStrings.option_share, GSYStrings.option_share, (model) {
4360
print("分享");
4461
}),
4562
];

‎pubspec.lock‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ packages:
199199
name: fluttertoast
200200
url: "https://pub.flutter-io.cn"
201201
source: hosted
202-
version: "2.0.6"
202+
version: "2.0.7"
203203
front_end:
204204
dependency: transitive
205205
description:
@@ -506,6 +506,13 @@ packages:
506506
url: "https://pub.flutter-io.cn"
507507
source: hosted
508508
version: "1.1.5"
509+
url_launcher:
510+
dependency: "direct main"
511+
description:
512+
name: url_launcher
513+
url: "https://pub.flutter-io.cn"
514+
source: hosted
515+
version: "3.0.3"
509516
utf:
510517
dependency: transitive
511518
description:

‎pubspec.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ dependencies:
1616
device_info: ^0.2.1
1717
connectivity: ^0.3.1
1818
flutter_markdown: ^0.1.5
19+
url_launcher: ^3.0.3
1920

2021
dev_dependencies:
2122
build_runner: ^0.7.6

0 commit comments

Comments
 (0)