Skip to content

Commit d2e75fb

Browse files
committed
增加honor list 显示
1 parent 6fd5327 commit d2e75fb

7 files changed

Lines changed: 243 additions & 66 deletions

File tree

‎lib/common/dao/repos_dao.dart‎

Lines changed: 118 additions & 44 deletions
Large diffs are not rendered by default.

‎lib/common/utils/navigator_utils.dart‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'package:gsy_github_app_flutter/page/code_detail_page_web.dart';
88
import 'package:gsy_github_app_flutter/page/common_list_page.dart';
99
import 'package:gsy_github_app_flutter/page/gsy_webview.dart';
1010
import 'package:gsy_github_app_flutter/page/home_page.dart';
11+
import 'package:gsy_github_app_flutter/page/honor_list_page.dart';
1112
import 'package:gsy_github_app_flutter/page/issue_detail_page.dart';
1213
import 'package:gsy_github_app_flutter/page/login_page.dart';
1314
import 'package:gsy_github_app_flutter/page/notify_page.dart';
@@ -60,6 +61,12 @@ class NavigatorUtils {
6061
widget: pageContainer(RepositoryDetailPage(userName, reposName))));
6162
}
6263

64+
///荣耀列表
65+
static Future goHonorListPage(BuildContext context, List list) {
66+
return Navigator.push(
67+
context, new SizeRoute(widget: pageContainer(HonorListPage(list))));
68+
}
69+
6370
///仓库版本列表
6471
static Future goReleasePage(BuildContext context, String userName,
6572
String reposName, String releaseUrl, String tagUrl) {
@@ -231,6 +238,7 @@ class NavigatorUtils {
231238
barrierDismissible: barrierDismissible,
232239
builder: (context) {
233240
return MediaQuery(
241+
234242
///不受系统字体缩放影响
235243
data: MediaQueryData.fromWindow(WidgetsBinding.instance.window)
236244
.copyWith(textScaleFactor: 1),

‎lib/page/honor_list_page.dart‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:gsy_github_app_flutter/common/dao/repos_dao.dart';
3+
import 'package:gsy_github_app_flutter/common/dao/user_dao.dart';
4+
import 'package:gsy_github_app_flutter/common/utils/common_utils.dart';
5+
import 'package:gsy_github_app_flutter/common/utils/navigator_utils.dart';
6+
import 'package:gsy_github_app_flutter/widget/state/base_person_state.dart';
7+
import 'package:gsy_github_app_flutter/widget/state/gsy_list_state.dart';
8+
import 'package:gsy_github_app_flutter/widget/pull/gsy_pull_load_widget.dart';
9+
import 'package:gsy_github_app_flutter/widget/repos_item.dart';
10+
import 'package:gsy_github_app_flutter/widget/user_item.dart';
11+
import 'package:provider/provider.dart';
12+
13+
/**
14+
* 荣耀list
15+
* Created by guoshuyu
16+
* on 2018/7/22.
17+
*/
18+
class HonorListPage extends StatefulWidget {
19+
20+
final List list;
21+
22+
HonorListPage(this.list);
23+
24+
@override
25+
_HonorListPageState createState() => _HonorListPageState();
26+
}
27+
28+
class _HonorListPageState extends State<HonorListPage> {
29+
_renderItem(item) {
30+
ReposViewModel reposViewModel = ReposViewModel.fromMap(item);
31+
return new ReposItem(reposViewModel, onPressed: () {
32+
NavigatorUtils.goReposDetail(
33+
context, reposViewModel.ownerName, reposViewModel.repositoryName);
34+
});
35+
}
36+
37+
@override
38+
Widget build(BuildContext context) {
39+
return new Scaffold(
40+
appBar: new AppBar(
41+
title: new Text(
42+
CommonUtils
43+
.getLocale(context)
44+
.user_tab_honor,
45+
maxLines: 1,
46+
overflow: TextOverflow.ellipsis,
47+
)),
48+
body: ListView.builder(
49+
itemBuilder: (context, index) {
50+
return _renderItem(widget.list[index]);
51+
},
52+
itemCount: widget.list.length,
53+
),);
54+
}
55+
}

‎lib/page/my_page.dart‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,7 @@ class _MyPageState extends BasePersonState<MyPage> {
100100
///获取用户组织信息
101101
getUserOrg(_getUserName());
102102
///获取用户仓库前100个star统计数据
103-
ReposDao.getUserRepository100StatusDao(_getUserName()).then((res) {
104-
if (res != null && res.result) {
105-
if (isShow) {
106-
setState(() {
107-
beStaredCount = res.data.toString();
108-
});
109-
}
110-
}
111-
});
103+
getHonor(_getUserName());
112104
_refreshNotify();
113105
}
114106
return await _getDataLogic();

‎lib/page/person_page.dart‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,7 @@ class _PersonState extends BasePersonState<PersonPage> {
8888
///获取当前用户的关注状态
8989
_getFocusStatus();
9090
///获取用户仓库前100个star统计数据
91-
ReposDao.getUserRepository100StatusDao(_getUserName()).then((res) {
92-
if (res != null && res.result) {
93-
if (isShow) {
94-
setState(() {
95-
beStaredCount = res.data.toString();
96-
});
97-
}
98-
}
99-
});
91+
getHonor(_getUserName());
10092
return null;
10193
}
10294

‎lib/widget/state/base_person_state.dart‎

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'dart:async';
22

33
import 'package:flutter/material.dart';
44
import 'package:flutter/rendering.dart';
5+
import 'package:gsy_github_app_flutter/common/dao/repos_dao.dart';
56
import 'package:gsy_github_app_flutter/common/dao/user_dao.dart';
67
import 'package:gsy_github_app_flutter/common/model/Event.dart';
78
import 'package:gsy_github_app_flutter/common/model/User.dart';
@@ -14,6 +15,7 @@ import 'package:gsy_github_app_flutter/widget/pull/nested/nested_refresh.dart';
1415
import 'package:gsy_github_app_flutter/widget/state/gsy_list_state.dart';
1516
import 'package:gsy_github_app_flutter/widget/user_header.dart';
1617
import 'package:gsy_github_app_flutter/widget/user_item.dart';
18+
import 'package:provider/provider.dart';
1719

1820
/**
1921
* Created by guoshuyu
@@ -30,6 +32,8 @@ abstract class BasePersonState<T extends StatefulWidget> extends State<T>
3032

3133
final List<UserOrg> orgList = new List();
3234

35+
final HonorModel honorModel = HonorModel();
36+
3337
@override
3438
showRefreshLoading() {
3539
new Future.delayed(const Duration(seconds: 0), () {
@@ -95,7 +99,8 @@ abstract class BasePersonState<T extends StatefulWidget> extends State<T>
9599
User userInfo, Color notifyColor, String beStaredCount, refreshCallBack) {
96100
double headerSize = 210;
97101
double bottomSize = 70;
98-
double chartSize = (userInfo.login != null && userInfo.type == "Organization") ? 70 : 215;
102+
double chartSize =
103+
(userInfo.login != null && userInfo.type == "Organization") ? 70 : 215;
99104
return <Widget>[
100105
///头部信息
101106
SliverPersistentHeader(
@@ -145,7 +150,18 @@ abstract class BasePersonState<T extends StatefulWidget> extends State<T>
145150
return SizedBox.expand(
146151
child: Padding(
147152
padding: EdgeInsets.only(bottom: 10, left: 0, right: 0),
148-
child: UserHeaderBottom(userInfo, beStaredCount, radius),
153+
/// MultiProvider 共享 HonorModel 状态
154+
child: MultiProvider(
155+
providers: [
156+
ChangeNotifierProvider(builder: (_) => honorModel),
157+
],
158+
child: Consumer<HonorModel>(
159+
builder: (context, honorModel, _) {
160+
return UserHeaderBottom(userInfo,
161+
honorModel.beStaredCount?.toString() ?? "---", radius, honorModel.honorList);
162+
},
163+
),
164+
),
149165
),
150166
);
151167
}),
@@ -174,4 +190,38 @@ abstract class BasePersonState<T extends StatefulWidget> extends State<T>
174190
),
175191
];
176192
}
193+
194+
///获取用户仓库前100个star统计数据
195+
getHonor(name) {
196+
ReposDao.getUserRepository100StatusDao(name).then((res) {
197+
if (res != null && res.result) {
198+
if (isShow) {
199+
///提交到 Provider HonorMode
200+
honorModel.beStaredCount = res.data["stared"];
201+
honorModel.honorList = res.data["list"];
202+
}
203+
}
204+
});
205+
}
206+
}
207+
208+
/// Provider HonorModel
209+
class HonorModel extends ChangeNotifier {
210+
int _beStaredCount;
211+
212+
int get beStaredCount => _beStaredCount;
213+
214+
set beStaredCount(int value) {
215+
_beStaredCount = value;
216+
notifyListeners();
217+
}
218+
219+
List _honorList;
220+
221+
List get honorList => _honorList;
222+
223+
set honorList(List value) {
224+
_honorList = value;
225+
notifyListeners();
226+
}
177227
}

‎lib/widget/user_header.dart‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,10 @@ class UserHeaderBottom extends StatelessWidget {
252252
final User userInfo;
253253
final String beStaredCount;
254254
final Radius radius;
255+
final List honorList;
255256

256-
UserHeaderBottom(this.userInfo, this.beStaredCount, this.radius);
257+
UserHeaderBottom(
258+
this.userInfo, this.beStaredCount, this.radius, this.honorList);
257259

258260
///底部状态栏
259261
_getBottomItem(String title, var value, onPressed) {
@@ -357,7 +359,11 @@ class UserHeaderBottom extends StatelessWidget {
357359
_getBottomItem(
358360
CommonUtils.getLocale(context).user_tab_honor,
359361
beStaredCount,
360-
() {},
362+
() {
363+
if (honorList != null) {
364+
NavigatorUtils.goHonorListPage(context, honorList);
365+
}
366+
},
361367
),
362368
],
363369
),

0 commit comments

Comments
 (0)