forked from CarGuo/gsy_github_app_flutter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserHeader.dart
More file actions
344 lines (321 loc) · 14.4 KB
/
UserHeader.dart
File metadata and controls
344 lines (321 loc) · 14.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
import 'package:flutter/material.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:gsy_github_app_flutter/common/localization/DefaultLocalizations.dart';
import 'package:gsy_github_app_flutter/common/model/User.dart';
import 'package:gsy_github_app_flutter/common/model/UserOrg.dart';
import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart';
import 'package:gsy_github_app_flutter/common/utils/CommonUtils.dart';
import 'package:gsy_github_app_flutter/common/utils/NavigatorUtils.dart';
import 'package:gsy_github_app_flutter/widget/GSYCardItem.dart';
import 'package:gsy_github_app_flutter/widget/GSYIConText.dart';
import 'package:gsy_github_app_flutter/widget/GSYUserIconWidget.dart';
/**
* 用户详情头部
* Created by guoshuyu
* Date: 2018-07-17
*/
class UserHeaderItem extends StatelessWidget {
final User userInfo;
final String beStaredCount;
final Color notifyColor;
final Color themeColor;
final VoidCallback refreshCallBack;
final List<UserOrg> orgList;
UserHeaderItem(this.userInfo, this.beStaredCount, this.themeColor, {this.notifyColor, this.refreshCallBack, this.orgList});
///底部状态栏
_getBottomItem(String title, var value, onPressed) {
String data = value == null ? "" : value.toString();
TextStyle valueStyle = (value != null && value.toString().length > 6) ? GSYConstant.minText : GSYConstant.smallSubLightText;
TextStyle titleStyle = (title != null && title.toString().length > 6) ? GSYConstant.minText : GSYConstant.smallSubLightText;
return new Expanded(
child: new Center(
child: new RawMaterialButton(
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
padding: EdgeInsets.only(top: 5.0),
constraints: const BoxConstraints(minWidth: 0.0, minHeight: 0.0),
child: RichText(
textAlign: TextAlign.center,
text: TextSpan(
children: [
TextSpan(text: title, style: titleStyle),
TextSpan(text: "\n", style: valueStyle),
TextSpan(text: data, style: valueStyle)
],
),
),
onPressed: onPressed)),
);
}
///通知ICon
_getNotifyIcon(BuildContext context, Color color) {
if (notifyColor == null) {
return Container();
}
return new RawMaterialButton(
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
padding: const EdgeInsets.only(top: 0.0, right: 5.0, left: 5.0),
constraints: const BoxConstraints(minWidth: 0.0, minHeight: 0.0),
child: new ClipOval(
child: new Icon(
GSYICons.USER_NOTIFY,
color: color,
size: 18.0,
),
),
onPressed: () {
NavigatorUtils.goNotifyPage(context).then((res) {
refreshCallBack?.call();
});
});
}
///用户组织
_renderOrgs(BuildContext context, List<UserOrg> orgList) {
if (orgList == null || orgList.length == 0) {
return new Container();
}
List<Widget> list = new List();
renderOrgsItem(UserOrg orgs) {
return GSYUserIconWidget(
padding: const EdgeInsets.only(right: 5.0, left: 5.0),
width: 30.0,
height: 30.0,
image: orgs.avatarUrl ?? GSYICons.DEFAULT_REMOTE_PIC,
onPressed: () {
NavigatorUtils.goPerson(context, orgs.login);
});
}
int length = orgList.length > 3 ? 3 : orgList.length;
list.add(new Text(CommonUtils.getLocale(context).user_orgs_title + ":", style: GSYConstant.smallSubLightText));
for (int i = 0; i < length; i++) {
list.add(renderOrgsItem(orgList[i]));
}
if (orgList.length > 3) {
list.add(new RawMaterialButton(
onPressed: () {
NavigatorUtils.gotoCommonList(context, userInfo.login + " " + CommonUtils.getLocale(context).user_orgs_title, "org", "user_orgs",
userName: userInfo.login);
},
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
padding: const EdgeInsets.only(right: 5.0, left: 5.0),
constraints: const BoxConstraints(minWidth: 0.0, minHeight: 0.0),
child: Icon(
Icons.more_horiz,
color: Color(GSYColors.white),
size: 18.0,
)));
}
return Row(children: list);
}
_renderChart(context) {
double height = 140.0;
double width = 3 * MediaQuery.of(context).size.width / 2;
if (userInfo.login != null && userInfo.type == "Organization") {
return new Container();
}
return (userInfo.login != null)
? new Card(
margin: EdgeInsets.only(top: 0.0, left: 10.0, right: 10.0, bottom: 10.0),
color: Color(GSYColors.white),
child: new SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: new Container(
padding: EdgeInsets.only(left: 10.0, right: 10.0),
width: width,
height: height,
///svg chart
child: new SvgPicture.network(
CommonUtils.getUserChartAddress(userInfo.login),
width: width,
height: height - 10,
allowDrawingOutsideViewBox: true,
placeholderBuilder: (BuildContext context) => new Container(
height: height,
width: width,
child: Center(
child: SpinKitRipple(color: Theme.of(context).primaryColor),
),
),
),
),
),
)
: new Container(
height: height,
child: Center(
child: SpinKitRipple(color: Theme.of(context).primaryColor),
),
);
}
@override
Widget build(BuildContext context) {
return new Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
new GSYCardItem(
color: themeColor,
margin: EdgeInsets.all(0.0),
shape: new RoundedRectangleBorder(borderRadius: BorderRadius.only(bottomLeft: Radius.circular(10.0), bottomRight: Radius.circular(10.0))),
child: new Padding(
padding: new EdgeInsets.only(left: 10.0, top: 10.0, right: 10.0, bottom: 10.0),
child: new Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
new Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
///用户头像
new RawMaterialButton(
onPressed: () {
if (userInfo.avatar_url != null) {
NavigatorUtils.gotoPhotoViewPage(context, userInfo.avatar_url);
}
},
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
padding: const EdgeInsets.all(0.0),
constraints: const BoxConstraints(minWidth: 0.0, minHeight: 0.0),
child: new ClipOval(
child: new FadeInImage.assetNetwork(
placeholder: GSYICons.DEFAULT_USER_ICON,
//预览图
fit: BoxFit.fitWidth,
image: userInfo.avatar_url ?? GSYICons.DEFAULT_REMOTE_PIC,
width: 80.0,
height: 80.0,
),
)),
new Padding(padding: EdgeInsets.all(10.0)),
new Expanded(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Row(
children: <Widget>[
///用户名
new Text(userInfo.login ?? "", style: GSYConstant.largeTextWhiteBold),
_getNotifyIcon(context, notifyColor),
],
),
new Text(userInfo.name == null ? "" : userInfo.name, style: GSYConstant.smallSubLightText),
///用户组织
new GSYIConText(
GSYICons.USER_ITEM_COMPANY,
userInfo.company ?? CommonUtils.getLocale(context).nothing_now,
GSYConstant.smallSubLightText,
Color(GSYColors.subLightTextColor),
10.0,
padding: 3.0,
),
///用户位置
new GSYIConText(
GSYICons.USER_ITEM_LOCATION,
userInfo.location ?? CommonUtils.getLocale(context).nothing_now,
GSYConstant.smallSubLightText,
Color(GSYColors.subLightTextColor),
10.0,
padding: 3.0,
),
],
),
),
],
),
new Container(
///用户博客
child: new RawMaterialButton(
onPressed: () {
if (userInfo.blog != null) {
CommonUtils.launchOutURL(userInfo.blog, context);
}
},
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
padding: const EdgeInsets.all(0.0),
constraints: const BoxConstraints(minWidth: 0.0, minHeight: 0.0),
child: new GSYIConText(
GSYICons.USER_ITEM_LINK,
userInfo.blog ?? CommonUtils.getLocale(context).nothing_now,
(userInfo.blog == null) ? GSYConstant.smallSubLightText : GSYConstant.smallActionLightText,
Color(GSYColors.subLightTextColor),
10.0,
padding: 3.0,
),
),
margin: new EdgeInsets.only(top: 6.0, bottom: 2.0),
alignment: Alignment.topLeft),
///组织
_renderOrgs(context, orgList),
///用户描述
new Container(
child: new Text(
userInfo.bio == null
? CommonUtils.getLocale(context).user_create_at + CommonUtils.getDateStr(userInfo.created_at)
: userInfo.bio + "\n" + CommonUtils.getLocale(context).user_create_at + CommonUtils.getDateStr(userInfo.created_at),
style: GSYConstant.smallSubLightText,
),
margin: new EdgeInsets.only(top: 6.0, bottom: 2.0),
alignment: Alignment.topLeft),
new Padding(padding: EdgeInsets.only(bottom: 5.0)),
new Divider(
color: Color(GSYColors.subLightTextColor),
),
///用户底部状态
new Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
_getBottomItem(
GSYLocalizations.of(context).currentLocalized.user_tab_repos,
userInfo.public_repos,
() {
NavigatorUtils.gotoCommonList(context, userInfo.login, "repository", "user_repos", userName: userInfo.login);
},
),
new Container(width: 0.3, height: 40.0, color: Color(GSYColors.subLightTextColor)),
_getBottomItem(
CommonUtils.getLocale(context).user_tab_fans,
userInfo.followers,
() {
NavigatorUtils.gotoCommonList(context, userInfo.login, "user", "follower", userName: userInfo.login);
},
),
new Container(width: 0.3, height: 40.0, color: Color(GSYColors.subLightTextColor)),
_getBottomItem(
CommonUtils.getLocale(context).user_tab_focus,
userInfo.following,
() {
NavigatorUtils.gotoCommonList(context, userInfo.login, "user", "followed", userName: userInfo.login);
},
),
new Container(width: 0.3, height: 40.0, color: Color(GSYColors.subLightTextColor)),
_getBottomItem(
CommonUtils.getLocale(context).user_tab_star,
userInfo.starred,
() {
NavigatorUtils.gotoCommonList(context, userInfo.login, "repository", "user_star", userName: userInfo.login);
},
),
new Container(width: 0.3, height: 40.0, color: Color(GSYColors.subLightTextColor)),
_getBottomItem(
CommonUtils.getLocale(context).user_tab_honor,
beStaredCount,
() {},
),
],
),
],
),
)),
new Container(
child: new Text(
(userInfo.type == "Organization")
? CommonUtils.getLocale(context).user_dynamic_group
: CommonUtils.getLocale(context).user_dynamic_title,
style: GSYConstant.normalTextBold,
overflow: TextOverflow.ellipsis,
),
margin: new EdgeInsets.only(top: 15.0, bottom: 15.0, left: 12.0),
alignment: Alignment.topLeft),
_renderChart(context),
],
);
}
}