X Tutup
Skip to content

Commit 18aec8d

Browse files
committed
add user header
1 parent f4e68f5 commit 18aec8d

File tree

5 files changed

+89
-98
lines changed

5 files changed

+89
-98
lines changed

lib/common/style/GSYStyle.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,19 @@ class GSYConstant {
167167
color: Color(GSYColors.TextColorWhite),
168168
fontSize: bigTextSize,
169169
);
170+
171+
static const largeTextWhiteBold = TextStyle(
172+
color: Color(GSYColors.TextColorWhite),
173+
fontSize: bigTextSize,
174+
fontWeight: FontWeight.bold,
175+
);
170176
}
171177

172178
class GSYStrings {
173179
static const String app_name = "GSYGithubAppFlutter";
174180

181+
static const String nothing_now = "目前什么都没有。";
182+
175183
static const String login_text = "登录";
176184

177185
static const String login_username_hint_text = "请输入github用户名";
@@ -198,4 +206,9 @@ class GSYICons {
198206
static IconData REPOS_ITEM_STAR = new IconData(0xe643, fontFamily: GSYICons.FONT_FAMILY);
199207
static IconData REPOS_ITEM_FORK = new IconData(0xe67e, fontFamily: GSYICons.FONT_FAMILY);
200208
static IconData REPOS_ITEM_ISSUE = new IconData(0xe661, fontFamily: GSYICons.FONT_FAMILY);
209+
210+
211+
static IconData USER_ITEM_COMPANY = new IconData(0xe63e, fontFamily: GSYICons.FONT_FAMILY);
212+
static IconData USER_ITEM_LOCATION = new IconData(0xe7e6, fontFamily: GSYICons.FONT_FAMILY);
213+
static IconData USER_ITEM_LINK = new IconData(0xe670, fontFamily: GSYICons.FONT_FAMILY);
201214
}

lib/page/MyPage.dart

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11

2+
import 'dart:async';
3+
24
import 'package:flutter/material.dart';
35
import 'package:flutter_redux/flutter_redux.dart';
46
import 'package:gsy_github_app_flutter/common/redux/GSYState.dart';
7+
import 'package:gsy_github_app_flutter/widget/GSYPullLoadWidget.dart';
58
import 'package:gsy_github_app_flutter/widget/UserHeader.dart';
9+
import 'package:redux/redux.dart';
610
class MyPage extends StatefulWidget {
711
@override
812
_MyPageState createState() => _MyPageState();
@@ -11,11 +15,38 @@ class MyPage extends StatefulWidget {
1115
// ignore: mixin_inherits_from_not_object
1216
class _MyPageState extends State<MyPage> with AutomaticKeepAliveClientMixin {
1317

18+
bool isLoading = false;
19+
20+
int page = 1;
21+
22+
final List dataList = new List();
23+
24+
final GSYPullLoadWidgetControl pullLoadWidgetControl = new GSYPullLoadWidgetControl();
25+
26+
Future<Null> _handleRefresh() async {
27+
return null;
28+
}
29+
30+
Future<Null> _onLoadMore() async {
31+
return null;
32+
}
33+
34+
_renderEventItem(userInfo, index) {
35+
if(index == 0) {
36+
return new UserHeaderItem(userInfo);
37+
}
38+
}
39+
40+
Store<GSYState> _getStore() {
41+
return StoreProvider.of(context);
42+
}
43+
1444
@override
1545
bool get wantKeepAlive => true;
1646

1747
@override
1848
void initState() {
49+
pullLoadWidgetControl.needHeader = true;
1950
super.initState();
2051
}
2152

@@ -24,14 +55,12 @@ class _MyPageState extends State<MyPage> with AutomaticKeepAliveClientMixin {
2455
super.didChangeDependencies();
2556
}
2657

27-
28-
2958
@override
3059
Widget build(BuildContext context) {
31-
return new StoreConnector<GSYState, String>(
32-
converter: (store) => store.state.userInfo.name,
33-
builder: (context, count) {
34-
return new UserHeaderItem();
60+
return new StoreBuilder<GSYState>(
61+
builder: (context, store) {
62+
return GSYPullLoadWidget(pullLoadWidgetControl, (BuildContext context, int index) => _renderEventItem(store.state.userInfo, index),
63+
_handleRefresh, _onLoadMore);
3564
},
3665
);
3766
}

lib/widget/GSYPullLoadWidget.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ class _GSYPullLoadWidgetState extends State<GSYPullLoadWidget> {
4747
super.initState();
4848
}
4949

50+
_getListCount() {
51+
if (control.needHeader) {
52+
return (control.dataList.length > 0) ? control.dataList.length + 2 : control.dataList.length + 1;
53+
} else {
54+
return (control.dataList.length > 0) ? control.dataList.length + 1 : control.dataList.length;
55+
}
56+
}
57+
5058
@override
5159
Widget build(BuildContext context) {
5260
return new RefreshIndicator(
@@ -60,7 +68,7 @@ class _GSYPullLoadWidgetState extends State<GSYPullLoadWidget> {
6068
return itemBuilder(context, index);
6169
}
6270
},
63-
itemCount: (control.dataList.length > 0) ? control.dataList.length + 1 : control.dataList.length,
71+
itemCount: _getListCount(),
6472
controller: _scrollController,
6573
),
6674
);
@@ -81,4 +89,5 @@ class _GSYPullLoadWidgetState extends State<GSYPullLoadWidget> {
8189
class GSYPullLoadWidgetControl {
8290
List dataList = new List();
8391
bool needLoadMore = true;
92+
bool needHeader = false;
8493
}

lib/widget/UserHeader.dart

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:flutter/material.dart';
2+
import 'package:gsy_github_app_flutter/common/model/User.dart';
23
import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart';
34
import 'package:gsy_github_app_flutter/widget/GSYCardItem.dart';
45
import 'package:gsy_github_app_flutter/widget/GSYIConText.dart';
@@ -8,6 +9,10 @@ import 'package:gsy_github_app_flutter/widget/GSYIConText.dart';
89
* Date: 2018-07-17
910
*/
1011
class UserHeaderItem extends StatelessWidget {
12+
final User userInfo;
13+
14+
UserHeaderItem(this.userInfo);
15+
1116
@override
1217
Widget build(BuildContext context) {
1318
return new Column(
@@ -30,7 +35,7 @@ class UserHeaderItem extends StatelessWidget {
3035
placeholder: "static/images/logo.png",
3136
//预览图
3237
fit: BoxFit.fitWidth,
33-
image: "fffffff",
38+
image: userInfo.avatar_url,
3439
width: 80.0,
3540
height: 80.0,
3641
),
@@ -40,26 +45,19 @@ class UserHeaderItem extends StatelessWidget {
4045
child: new Column(
4146
crossAxisAlignment: CrossAxisAlignment.start,
4247
children: <Widget>[
43-
new Text("Login", style: GSYConstant.normalTextBold),
44-
new GSYIConText(
45-
GSYICons.REPOS_ITEM_USER,
46-
"Name ",
47-
GSYConstant.subLightSmallText,
48-
Color(GSYColors.subLightTextColor),
49-
10.0,
50-
padding: 3.0,
51-
),
48+
new Text(userInfo.login, style: GSYConstant.largeTextWhiteBold),
49+
new Text(userInfo.name, style: GSYConstant.subLightSmallText),
5250
new GSYIConText(
53-
GSYICons.REPOS_ITEM_USER,
54-
"company ",
51+
GSYICons.USER_ITEM_COMPANY,
52+
userInfo.company == null ? GSYStrings.nothing_now : userInfo.company,
5553
GSYConstant.subLightSmallText,
5654
Color(GSYColors.subLightTextColor),
5755
10.0,
5856
padding: 3.0,
5957
),
6058
new GSYIConText(
61-
GSYICons.REPOS_ITEM_USER,
62-
"location ",
59+
GSYICons.USER_ITEM_LOCATION,
60+
userInfo.location == null ? GSYStrings.nothing_now : userInfo.location,
6361
GSYConstant.subLightSmallText,
6462
Color(GSYColors.subLightTextColor),
6563
10.0,
@@ -71,19 +69,20 @@ class UserHeaderItem extends StatelessWidget {
7169
],
7270
),
7371
new Container(
74-
child: new Text(
75-
"link",
76-
style: GSYConstant.subSmallText,
77-
maxLines: 3,
78-
overflow: TextOverflow.ellipsis,
72+
child: new GSYIConText(
73+
GSYICons.USER_ITEM_LINK,
74+
userInfo.blog == null ? GSYStrings.nothing_now : userInfo.blog,
75+
GSYConstant.subLightSmallText,
76+
Color(GSYColors.subLightTextColor),
77+
10.0,
78+
padding: 3.0,
7979
),
8080
margin: new EdgeInsets.only(top: 6.0, bottom: 2.0),
8181
alignment: Alignment.topLeft),
8282
new Container(
8383
child: new Text(
84-
"desssssssssssss",
85-
style: GSYConstant.subSmallText,
86-
maxLines: 3,
84+
userInfo.bio == null ? GSYStrings.nothing_now : userInfo.bio,
85+
style: GSYConstant.subLightSmallText,
8786
overflow: TextOverflow.ellipsis,
8887
),
8988
margin: new EdgeInsets.only(top: 6.0, bottom: 2.0),
@@ -94,27 +93,31 @@ class UserHeaderItem extends StatelessWidget {
9493
children: <Widget>[
9594
new Expanded(
9695
child: new Center(
97-
child: new Text("fff\nff"),
96+
child: new Text("仓库\n" + userInfo.public_repos.toString(), textAlign: TextAlign.center, style: GSYConstant.subSmallText),
9897
),
9998
),
10099
new Expanded(
101100
child: new Center(
102-
child: new Text("fff\nff"),
101+
child: new Text("粉丝\n" + userInfo.followers.toString(), textAlign: TextAlign.center, style: GSYConstant.subSmallText),
103102
),
104103
),
105104
new Expanded(
106105
child: new Center(
107-
child: new Text("fff\nff"),
106+
child: new Text(
107+
"关注\n" + userInfo.following.toString(),
108+
textAlign: TextAlign.center,
109+
style: GSYConstant.subSmallText,
110+
),
108111
),
109112
),
110113
new Expanded(
111114
child: new Center(
112-
child: new Text("fff\nff"),
115+
child: new Text("星标\n---", textAlign: TextAlign.center, style: GSYConstant.subSmallText),
113116
),
114117
),
115118
new Expanded(
116119
child: new Center(
117-
child: new Text("fff\nff"),
120+
child: new Text("荣耀\n---", textAlign: TextAlign.center, style: GSYConstant.subSmallText),
118121
),
119122
),
120123
],

pubspec.lock

Lines changed: 1 addition & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,6 @@ packages:
7171
url: "https://pub.flutter-io.cn"
7272
source: hosted
7373
version: "5.5.3"
74-
cached_network_image:
75-
dependency: transitive
76-
description:
77-
name: cached_network_image
78-
url: "https://pub.flutter-io.cn"
79-
source: hosted
80-
version: "0.4.1+1"
8174
charcode:
8275
dependency: transitive
8376
description:
@@ -167,27 +160,6 @@ packages:
167160
description: flutter
168161
source: sdk
169162
version: "0.0.0"
170-
flutter_cache_manager:
171-
dependency: transitive
172-
description:
173-
name: flutter_cache_manager
174-
url: "https://pub.flutter-io.cn"
175-
source: hosted
176-
version: "0.1.1"
177-
flutter_custom_tabs:
178-
dependency: transitive
179-
description:
180-
name: flutter_custom_tabs
181-
url: "https://pub.flutter-io.cn"
182-
source: hosted
183-
version: "0.1.0"
184-
flutter_html_view:
185-
dependency: "direct main"
186-
description:
187-
name: flutter_html_view
188-
url: "https://pub.flutter-io.cn"
189-
source: hosted
190-
version: "0.5.2"
191163
flutter_redux:
192164
dependency: "direct main"
193165
description:
@@ -354,13 +326,6 @@ packages:
354326
url: "https://pub.flutter-io.cn"
355327
source: hosted
356328
version: "1.5.1"
357-
path_provider:
358-
dependency: transitive
359-
description:
360-
name: path_provider
361-
url: "https://pub.flutter-io.cn"
362-
source: hosted
363-
version: "0.4.1"
364329
plugin:
365330
dependency: transitive
366331
description:
@@ -492,13 +457,6 @@ packages:
492457
url: "https://pub.flutter-io.cn"
493458
source: hosted
494459
version: "1.0.2"
495-
synchronized:
496-
dependency: transitive
497-
description:
498-
name: synchronized
499-
url: "https://pub.flutter-io.cn"
500-
source: hosted
501-
version: "1.5.0+1"
502460
term_glyph:
503461
dependency: transitive
504462
description:
@@ -520,41 +478,20 @@ packages:
520478
url: "https://pub.flutter-io.cn"
521479
source: hosted
522480
version: "1.1.5"
523-
url_launcher:
524-
dependency: transitive
525-
description:
526-
name: url_launcher
527-
url: "https://pub.flutter-io.cn"
528-
source: hosted
529-
version: "3.0.3"
530481
utf:
531482
dependency: transitive
532483
description:
533484
name: utf
534485
url: "https://pub.flutter-io.cn"
535486
source: hosted
536487
version: "0.9.0+4"
537-
uuid:
538-
dependency: transitive
539-
description:
540-
name: uuid
541-
url: "https://pub.flutter-io.cn"
542-
source: hosted
543-
version: "0.5.3"
544488
vector_math:
545489
dependency: transitive
546490
description:
547491
name: vector_math
548492
url: "https://pub.flutter-io.cn"
549493
source: hosted
550494
version: "2.0.6"
551-
video_player:
552-
dependency: transitive
553-
description:
554-
name: video_player
555-
url: "https://pub.flutter-io.cn"
556-
source: hosted
557-
version: "0.5.4"
558495
watcher:
559496
dependency: transitive
560497
description:
@@ -578,4 +515,4 @@ packages:
578515
version: "2.1.13"
579516
sdks:
580517
dart: ">=2.0.0-dev.54.0 <=2.0.0-dev.58.0.flutter-f981f09760"
581-
flutter: ">=0.2.5 <2.0.0"
518+
flutter: ">=0.1.4 <2.0.0"

0 commit comments

Comments
 (0)
X Tutup