Skip to content

Commit 2d3d49c

Browse files
committed
增加个人信息
1 parent 1b10cb4 commit 2d3d49c

7 files changed

Lines changed: 140 additions & 13 deletions

File tree

‎VERSION.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
* webview点击跳转。
1313
* markdown htmlview 表格。
1414

15-
* 未读的通知进去issue提示其他异常
1615

1716
### 1.0.7(进行中)
1817
* 增加图片预览
18+
* 修复未读的通知打开提示其他异常
1919

2020
### 1.0.6
2121
* trend修改为redux

‎lib/common/dao/UserDao.dart‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,4 +299,21 @@ class UserDao {
299299
return new DataResult(null, false);
300300
}
301301
}
302+
303+
/**
304+
* 更新用户信息
305+
*/
306+
static updateUserDao(params, Store store) async {
307+
String url = Address.getMyUserInfo();
308+
var res = await HttpManager.netFetch(url, params, null, new Options(method: "PATCH"));
309+
if (res != null && res.result) {
310+
var localResult = await getUserInfoLocal();
311+
User newUser = User.fromJson(res.data);
312+
newUser.starred = localResult.data.starred;
313+
await LocalStorage.save(Config.USER_INFO, json.encode(newUser.toJson()));
314+
store.dispatch(new UpdateUserAction(newUser));
315+
return new DataResult(newUser, true);
316+
}
317+
return new DataResult(null, false);
318+
}
302319
}

‎lib/common/style/GSYStyle.dart‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ class GSYStrings {
252252
static const String home_about = "关于";
253253
static const String home_check_update = "检测更新";
254254
static const String home_history = "阅读历史";
255+
static const String home_user_info = "个人信息";
255256

256257
static const String login_username_hint_text = "请输入github用户名";
257258
static const String login_password_hint_text = "请输入密码";
@@ -334,6 +335,14 @@ class GSYStrings {
334335

335336
static const String release_tab_release = "版本";
336337
static const String release_tab_tag = "标记";
338+
339+
340+
static const String user_profile_name = "名字";
341+
static const String user_profile_email = "邮箱";
342+
static const String user_profile_link = "链接";
343+
static const String user_profile_org = "公司";
344+
static const String user_profile_location = "位置";
345+
static const String user_profile_info = "简介";
337346
}
338347

339348
class GSYICons {

‎lib/common/utils/NavigatorUtils.dart‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import 'package:gsy_github_app_flutter/page/PushDetailPage.dart';
1616
import 'package:gsy_github_app_flutter/page/ReleasePage.dart';
1717
import 'package:gsy_github_app_flutter/page/RepositoryDetailPage.dart';
1818
import 'package:gsy_github_app_flutter/page/SearchPage.dart';
19+
import 'package:gsy_github_app_flutter/page/UserProfilePage.dart';
20+
import 'package:path/path.dart';
1921

2022
/**
2123
* 导航栏
@@ -188,4 +190,9 @@ class NavigatorUtils {
188190
static gotoPhotoViewPage(BuildContext context, String url) {
189191
Navigator.push(context, new MaterialPageRoute(builder: (context) => new PhotoViewPage(url)));
190192
}
193+
194+
///用户配置
195+
static gotoUserProfileInfo(BuildContext context) {
196+
Navigator.push(context, new MaterialPageRoute(builder: (context) => new UserProfileInfo()));
197+
}
191198
}

‎lib/page/TrendPage.dart‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ class _TrendPageState extends GSYListState<TrendPage> {
155155
),
156156
);
157157
},
158-
);;
158+
);
159159
}
160160
}
161161

‎lib/page/UserProfilePage.dart‎

Lines changed: 97 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,118 @@
11
import 'package:flutter/material.dart';
2+
import 'package:flutter_redux/flutter_redux.dart';
3+
import 'package:gsy_github_app_flutter/common/dao/UserDao.dart';
4+
import 'package:gsy_github_app_flutter/common/model/User.dart';
5+
import 'package:gsy_github_app_flutter/common/redux/GSYState.dart';
6+
import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart';
7+
import 'package:gsy_github_app_flutter/common/utils/CommonUtils.dart';
8+
import 'package:gsy_github_app_flutter/widget/GSYCardItem.dart';
9+
import 'package:redux/redux.dart';
210

311
/**
12+
* 用户信息中心
413
* Created by guoshuyu
514
* Date: 2018-08-08
615
*/
716

8-
class UserProfile extends StatefulWidget {
17+
class UserProfileInfo extends StatefulWidget {
18+
UserProfileInfo();
19+
920
@override
1021
_UserProfileState createState() => _UserProfileState();
1122
}
1223

13-
class _UserProfileState extends State<UserProfile> {
24+
class _UserProfileState extends State<UserProfileInfo> {
25+
_renderItem(IconData leftIcon, String title, String value, VoidCallback onPressed) {
26+
return new GSYCardItem(
27+
child: new RawMaterialButton(
28+
onPressed: onPressed,
29+
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
30+
padding: const EdgeInsets.all(15.0),
31+
constraints: const BoxConstraints(minWidth: 0.0, minHeight: 0.0),
32+
child: new Row(
33+
children: <Widget>[
34+
new Icon(leftIcon),
35+
new Container(
36+
width: 10.0,
37+
),
38+
new Text(title, style: GSYConstant.subNormalText),
39+
new Container(
40+
width: 10.0,
41+
),
42+
new Expanded(child: new Text(value, style: GSYConstant.normalText)),
43+
new Container(
44+
width: 10.0,
45+
),
46+
new Icon(GSYICons.REPOS_ITEM_NEXT, size: 12.0),
47+
],
48+
),
49+
),
50+
);
51+
}
1452

15-
_renderList() {
16-
return [
53+
static const String user_profile_name = "名字";
54+
static const String user_profile_email = "邮箱";
55+
static const String user_profile_link = "链接";
56+
static const String user_profile_org = "公司";
57+
static const String user_profile_location = "位置";
58+
static const String user_profile_info = "简介";
1759

60+
_showEditDialog(String title, String value, String key, Store store) {
61+
String content = value ?? "";
62+
CommonUtils.showEditDialog(context, title, (title) {}, (res) {
63+
content = res;
64+
}, () {
65+
if (content == null || content.length == 0) {
66+
return;
67+
}
68+
CommonUtils.showLoadingDialog(context);
69+
70+
UserDao.updateUserDao({key: content}, store).then((res) {
71+
Navigator.of(context).pop();
72+
if(res != null && res.result) {
73+
Navigator.of(context).pop();
74+
}
75+
});
76+
}, titleController: new TextEditingController(), valueController: new TextEditingController(text: value), needTitle: false);
77+
}
78+
79+
List<Widget> _renderList(User userInfo, Store store) {
80+
return [
81+
_renderItem(Icons.info, GSYStrings.user_profile_name, userInfo.name ?? "---", () {
82+
_showEditDialog(GSYStrings.user_profile_name, userInfo.name, "name", store);
83+
}),
84+
_renderItem(Icons.email, GSYStrings.user_profile_email, userInfo.email ?? "---", () {
85+
_showEditDialog(GSYStrings.user_profile_email, userInfo.email, "email", store);
86+
}),
87+
_renderItem(Icons.link, GSYStrings.user_profile_link, userInfo.blog ?? "---", () {
88+
_showEditDialog(GSYStrings.user_profile_link, userInfo.blog, "blog", store);
89+
}),
90+
_renderItem(Icons.group, GSYStrings.user_profile_org, userInfo.company ?? "---", () {
91+
_showEditDialog(GSYStrings.user_profile_org, userInfo.company, "company", store);
92+
}),
93+
_renderItem(Icons.location_on, GSYStrings.user_profile_location, userInfo.location ?? "---", () {
94+
_showEditDialog(GSYStrings.user_profile_location, userInfo.location, "location", store);
95+
}),
96+
_renderItem(Icons.message, GSYStrings.user_profile_info, userInfo.bio ?? "---", () {
97+
_showEditDialog(GSYStrings.user_profile_info, userInfo.bio, "bio", store);
98+
}),
1899
];
19100
}
20101

21102
@override
22103
Widget build(BuildContext context) {
23-
return new Container(
24-
color: Colors.white,
25-
child: new SingleChildScrollView(
26-
child: new Column(
27-
children: _renderList(),
104+
return new StoreBuilder<GSYState>(builder: (context, store) {
105+
return Scaffold(
106+
appBar: new AppBar(title: new Text(GSYStrings.home_user_info)),
107+
body: new Container(
108+
color: Colors.white,
109+
child: new SingleChildScrollView(
110+
child: new Column(
111+
children: _renderList(store.state.userInfo, store),
112+
),
113+
),
28114
),
29-
),
30-
);
115+
);
116+
});
31117
}
32118
}

‎lib/widget/HomeDrawer.dart‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,14 @@ class HomeDrawer extends StatelessWidget {
101101
onTap: () {
102102
NavigatorUtils.gotoCommonList(context, GSYStrings.home_history, "repository", "history", userName: "", reposName: "");
103103
}),
104+
new ListTile(
105+
title: new Text(
106+
GSYStrings.home_user_info,
107+
style: GSYConstant.normalText,
108+
),
109+
onTap: () {
110+
NavigatorUtils.gotoUserProfileInfo(context);
111+
}),
104112
new ListTile(
105113
title: new Text(
106114
GSYStrings.home_check_update,

0 commit comments

Comments
 (0)