|
1 | 1 | 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'; |
2 | 10 |
|
3 | 11 | /** |
| 12 | + * 用户信息中心 |
4 | 13 | * Created by guoshuyu |
5 | 14 | * Date: 2018-08-08 |
6 | 15 | */ |
7 | 16 |
|
8 | | -class UserProfile extends StatefulWidget { |
| 17 | +class UserProfileInfo extends StatefulWidget { |
| 18 | + UserProfileInfo(); |
| 19 | + |
9 | 20 | @override |
10 | 21 | _UserProfileState createState() => _UserProfileState(); |
11 | 22 | } |
12 | 23 |
|
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 | + } |
14 | 52 |
|
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 = "简介"; |
17 | 59 |
|
| 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 | + }), |
18 | 99 | ]; |
19 | 100 | } |
20 | 101 |
|
21 | 102 | @override |
22 | 103 | 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 | + ), |
28 | 114 | ), |
29 | | - ), |
30 | | - ); |
| 115 | + ); |
| 116 | + }); |
31 | 117 | } |
32 | 118 | } |
0 commit comments