Skip to content

Commit 75c88a3

Browse files
committed
bottom widget
1 parent bad3e63 commit 75c88a3

11 files changed

Lines changed: 181 additions & 32 deletions

‎lib/common/dao/ReposDao.dart‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,17 @@ class ReposDao {
8585
return new DataResult(null, false);
8686
}
8787
}
88+
89+
/**
90+
* 获取用户对当前仓库的star、watcher状态
91+
*/
92+
static getRepositoryStatusDao(userName, reposName) async {
93+
String urls = Address.resolveStarRepos(userName, reposName);
94+
String urlw = Address.resolveWatcherRepos(userName, reposName);
95+
var resS = await HttpManager.netFetch(urls, null, null, null, noTip: true);
96+
var resW = await HttpManager.netFetch(urlw, null, null, null, noTip: true);
97+
var data = {"star": resS.result, "watch": resW.result};
98+
return new DataResult(data, true);
99+
}
100+
88101
}

‎lib/common/net/Api.dart‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ class HttpManager {
2323
///[ params] 请求参数
2424
///[ header] 外加头
2525
///[ option] 配置
26-
static netFetch(url, params, Map<String, String> header, Options option) async {
26+
static netFetch(url, params, Map<String, String> header, Options option, {noTip = false}) async {
2727

2828
//没有网络
2929
var connectivityResult = await (new Connectivity().checkConnectivity());
3030
if (connectivityResult == ConnectivityResult.none) {
31-
return new ResultData(Code.errorHandleFunction(Code.NETWORK_ERROR, ""), false, Code.NETWORK_ERROR);
31+
return new ResultData(Code.errorHandleFunction(Code.NETWORK_ERROR, "", noTip), false, Code.NETWORK_ERROR);
3232
}
3333

3434
Map<String, String> headers = new HashMap();
@@ -71,7 +71,7 @@ class HttpManager {
7171
print('请求异常: ' + e.toString());
7272
print('请求异常url: ' + url);
7373
}
74-
return new ResultData(Code.errorHandleFunction(errorResponse.statusCode, e.message), false, errorResponse.statusCode);
74+
return new ResultData(Code.errorHandleFunction(errorResponse.statusCode, e.message, noTip), false, errorResponse.statusCode);
7575
}
7676

7777
if (Config.DEBUG) {
@@ -104,7 +104,7 @@ class HttpManager {
104104
print(e.toString() + url);
105105
return new ResultData(response.data, false, response.statusCode, headers: response.headers);
106106
}
107-
return new ResultData(Code.errorHandleFunction(response.statusCode, ""), false, response.statusCode);
107+
return new ResultData(Code.errorHandleFunction(response.statusCode, "", noTip), false, response.statusCode);
108108
}
109109

110110
///清除授权

‎lib/common/net/Code.dart‎

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,42 @@ class Code {
1414

1515
static const SUCCESS = 200;
1616

17-
static errorHandleFunction(code, message) {
17+
static errorHandleFunction(code, message, noTip) {
1818
switch (code) {
1919
case NETWORK_ERROR:
20-
Fluttertoast.showToast(msg: GSYStrings.network_error);
20+
if(!noTip) {
21+
Fluttertoast.showToast(msg: GSYStrings.network_error);
22+
}
2123
return GSYStrings.network_error;
2224
case 401:
2325
//TODO 授权逻辑
2426
/*if (Actions.currentScene !== 'LoginPage') {
2527
Actions.reset("LoginPage");
2628
}*/
27-
Fluttertoast.showToast(msg: GSYStrings.network_error_401);
29+
if(!noTip) {
30+
Fluttertoast.showToast(msg: GSYStrings.network_error_401);
31+
}
2832
return GSYStrings.network_error_401; //401 Unauthorized
2933
case 403:
30-
Fluttertoast.showToast(msg: GSYStrings.network_error_403);
34+
if(!noTip) {
35+
Fluttertoast.showToast(msg: GSYStrings.network_error_403);
36+
}
3137
return GSYStrings.network_error_403;
3238
case 404:
33-
Fluttertoast.showToast(msg: GSYStrings.network_error_404);
39+
if(!noTip) {
40+
Fluttertoast.showToast(msg: GSYStrings.network_error_404);
41+
}
3442
return GSYStrings.network_error_404;
3543
case NETWORK_TIMEOUT:
3644
//超时
37-
Fluttertoast.showToast(msg: GSYStrings.network_error_timeout);
45+
if(!noTip) {
46+
Fluttertoast.showToast(msg: GSYStrings.network_error_timeout);
47+
}
3848
return GSYStrings.network_error_timeout;
3949
default:
40-
Fluttertoast.showToast(msg: GSYStrings.network_error_unknown + " " + message);
50+
if(!noTip) {
51+
Fluttertoast.showToast(msg: GSYStrings.network_error_unknown + " " + message);
52+
}
4153
return GSYStrings.network_error_unknown;
4254
}
4355
}

‎lib/common/style/GSYStyle.dart‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,10 @@ class GSYConstant {
143143
fontSize: normalTextSize,
144144
);
145145

146-
static const normalTextMitWhite = TextStyle(
146+
static const normalTextMitWhiteBold = TextStyle(
147147
color: Color(GSYColors.miWhite),
148148
fontSize: normalTextSize,
149+
fontWeight: FontWeight.bold
149150
);
150151

151152
static const normalTextLight = TextStyle(
@@ -234,6 +235,11 @@ class GSYICons {
234235
static IconData REPOS_ITEM_FORK = new IconData(0xe67e, fontFamily: GSYICons.FONT_FAMILY);
235236
static IconData REPOS_ITEM_ISSUE = new IconData(0xe661, fontFamily: GSYICons.FONT_FAMILY);
236237

238+
239+
static IconData REPOS_ITEM_STARED = new IconData(0xe698, fontFamily: GSYICons.FONT_FAMILY);
240+
static IconData REPOS_ITEM_WATCH = new IconData(0xe681, fontFamily: GSYICons.FONT_FAMILY);
241+
static IconData REPOS_ITEM_WATCHED = new IconData(0xee629, fontFamily: GSYICons.FONT_FAMILY);
242+
237243
static IconData USER_ITEM_COMPANY = new IconData(0xe63e, fontFamily: GSYICons.FONT_FAMILY);
238244
static IconData USER_ITEM_LOCATION = new IconData(0xe7e6, fontFamily: GSYICons.FONT_FAMILY);
239245
static IconData USER_ITEM_LINK = new IconData(0xe670, fontFamily: GSYICons.FONT_FAMILY);

‎lib/page/DynamicPage.dart‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ class _DynamicPageState extends State<DynamicPage> with AutomaticKeepAliveClient
9191

9292
@override
9393
Widget build(BuildContext context) {
94+
super.build(context); // See AutomaticKeepAliveClientMixin.
9495
return new StoreBuilder<GSYState>(
9596
builder: (context, store) {
9697
return GSYPullLoadWidget(pullLoadWidgetControl, (BuildContext context, int index) => _renderEventItem(pullLoadWidgetControl.dataList[index]),

‎lib/page/MyPage.dart‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ class _MyPageState extends State<MyPage> with AutomaticKeepAliveClientMixin {
112112

113113
@override
114114
Widget build(BuildContext context) {
115+
super.build(context); // See AutomaticKeepAliveClientMixin.
115116
return new StoreBuilder<GSYState>(
116117
builder: (context, store) {
117118
return GSYPullLoadWidget(

‎lib/page/RepositoryDetailPage.dart‎

Lines changed: 89 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'package:gsy_github_app_flutter/common/dao/ReposDao.dart';
33
import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart';
44
import 'package:gsy_github_app_flutter/page/RepositoryDetailReadmePage.dart';
55
import 'package:gsy_github_app_flutter/page/RepostoryDetailInfoPage.dart';
6+
import 'package:gsy_github_app_flutter/widget/GSYIConText.dart';
67
import 'package:gsy_github_app_flutter/widget/GSYTabBarWidget.dart';
78
import 'package:gsy_github_app_flutter/widget/ReposHeaderItem.dart';
89

@@ -24,15 +25,19 @@ class RepositoryDetailPage extends StatefulWidget {
2425
}
2526

2627
// ignore: mixin_inherits_from_not_object
27-
class _RepositoryDetailPageState extends State<RepositoryDetailPage> with AutomaticKeepAliveClientMixin {
28+
class _RepositoryDetailPageState extends State<RepositoryDetailPage> {
2829
ReposHeaderViewModel reposHeaderViewModel = new ReposHeaderViewModel();
2930

31+
BottomStatusModel bottomStatusModel;
32+
3033
final String userName;
3134

3235
final String reposName;
3336

3437
final ReposDetailInfoPageControl reposDetailInfoPageControl = new ReposDetailInfoPageControl();
3538

39+
final TarWidgetControl tarBarControl = new TarWidgetControl();
40+
3641
_RepositoryDetailPageState(this.userName, this.reposName);
3742

3843
_getReposDetail() async {
@@ -44,19 +49,86 @@ class _RepositoryDetailPageState extends State<RepositoryDetailPage> with Automa
4449
}
4550
}
4651

47-
@override
48-
void didChangeDependencies() {
49-
this._getReposDetail();
50-
super.didChangeDependencies();
52+
_getReposStatus() async {
53+
var result = await ReposDao.getRepositoryStatusDao(userName, reposName);
54+
print(result.data["star"]);
55+
print(result.data["watch"]);
56+
String watchText = result.data["watch"] ? "UnWatch" : "Watch";
57+
String starText = result.data["star"] ? "UnStar" : "Star";
58+
IconData watchIcon = result.data["watch"] ? GSYICons.REPOS_ITEM_WATCHED : GSYICons.REPOS_ITEM_WATCH;
59+
IconData starIcon = result.data["star"] ? GSYICons.REPOS_ITEM_STARED : GSYICons.REPOS_ITEM_STAR;
60+
BottomStatusModel model = new BottomStatusModel(watchText, starText, watchIcon, starIcon, result.data["watch"], result.data["star"]);
61+
bottomStatusModel = model;
62+
setState(() {
63+
tarBarControl.footerButton = _getBottomWidget();
64+
});
65+
}
66+
67+
_getBottomWidget() {
68+
List<Widget> bottomWidget = (bottomStatusModel == null)
69+
? []
70+
: <Widget>[
71+
new FlatButton(
72+
onPressed: () => {},
73+
child: new GSYIConText(
74+
bottomStatusModel.starIcon,
75+
bottomStatusModel.starText,
76+
GSYConstant.smallText,
77+
Color(GSYColors.primaryValue),
78+
15.0,
79+
padding: 5.0,
80+
mainAxisAlignment: MainAxisAlignment.center,
81+
)),
82+
new FlatButton(
83+
onPressed: () {},
84+
child: new GSYIConText(
85+
bottomStatusModel.watchIcon,
86+
bottomStatusModel.watchText,
87+
GSYConstant.smallText,
88+
Color(GSYColors.primaryValue),
89+
15.0,
90+
padding: 5.0,
91+
mainAxisAlignment: MainAxisAlignment.center,
92+
)),
93+
new FlatButton(
94+
onPressed: () {},
95+
child: new GSYIConText(
96+
GSYICons.REPOS_ITEM_FORK,
97+
"fork",
98+
GSYConstant.smallText,
99+
Color(GSYColors.primaryValue),
100+
15.0,
101+
padding: 5.0,
102+
mainAxisAlignment: MainAxisAlignment.center,
103+
)),
104+
new FlatButton(
105+
onPressed: () {},
106+
color: Color(GSYColors.primaryValue),
107+
child: new GSYIConText(
108+
Icons.arrow_drop_up,
109+
"master",
110+
GSYConstant.smallTextWhite,
111+
Color(GSYColors.white),
112+
30.0,
113+
padding: 3.0,
114+
mainAxisAlignment: MainAxisAlignment.center,
115+
))
116+
];
117+
return bottomWidget;
51118
}
52119

53120
@override
54-
bool get wantKeepAlive => true;
121+
void initState() {
122+
super.initState();
123+
this._getReposDetail();
124+
this._getReposStatus();
125+
}
55126

56127
@override
57128
Widget build(BuildContext context) {
58129
return new GSYTabBarWidget(
59130
type: GSYTabBarWidget.TOP_TAB,
131+
tarWidgetControl: tarBarControl,
60132
tabItems: [
61133
new Tab(text: GSYStrings.repos_tab_readme),
62134
new Tab(text: GSYStrings.repos_tab_info),
@@ -74,3 +146,14 @@ class _RepositoryDetailPageState extends State<RepositoryDetailPage> with Automa
74146
title: reposName);
75147
}
76148
}
149+
150+
class BottomStatusModel {
151+
final String watchText;
152+
final String starText;
153+
final IconData watchIcon;
154+
final IconData starIcon;
155+
final bool star;
156+
final bool watch;
157+
158+
BottomStatusModel(this.watchText, this.starText, this.watchIcon, this.starIcon, this.watch, this.star);
159+
}

‎lib/page/RepostoryDetailInfoPage.dart‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,21 +101,22 @@ class _ReposDetailInfoPageState extends State<ReposDetailInfoPage> with Automati
101101

102102
@override
103103
void initState() {
104-
pullLoadWidgetControl.needHeader = true;
105104
super.initState();
106-
}
107-
108-
@override
109-
void didChangeDependencies() {
105+
pullLoadWidgetControl.needHeader = true;
110106
pullLoadWidgetControl.dataList = dataList;
111107
if (pullLoadWidgetControl.dataList.length == 0) {
112108
_handleRefresh();
113109
}
110+
}
111+
112+
@override
113+
void didChangeDependencies() {
114114
super.didChangeDependencies();
115115
}
116116

117117
@override
118118
Widget build(BuildContext context) {
119+
super.build(context); // See AutomaticKeepAliveClientMixin.
119120
return GSYPullLoadWidget(pullLoadWidgetControl, (BuildContext context, int index) => _renderEventItem(index), _handleRefresh, _onLoadMore);
120121
}
121122
}

‎lib/page/TrendPage.dart‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class _TrendPageState extends State<TrendPage> with AutomaticKeepAliveClientMixi
7373

7474
@override
7575
Widget build(BuildContext context) {
76+
super.build(context); // See AutomaticKeepAliveClientMixin.
7677
return GSYPullLoadWidget(
7778
pullLoadWidgetControl, (BuildContext context, int index) => _renderItem(pullLoadWidgetControl.dataList[index]), _handleRefresh, _onLoadMore);
7879
}

‎lib/widget/GSYTabBarWidget.dart‎

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,26 @@ class GSYTabBarWidget extends StatefulWidget {
2323

2424
final Widget drawer;
2525

26-
GSYTabBarWidget({Key key, this.type, this.tabItems, this.tabViews, this.backgroundColor, this.indicatorColor, this.title, this.drawer})
26+
final Widget floatingActionButton;
27+
28+
final TarWidgetControl tarWidgetControl;
29+
30+
GSYTabBarWidget(
31+
{Key key,
32+
this.type,
33+
this.tabItems,
34+
this.tabViews,
35+
this.backgroundColor,
36+
this.indicatorColor,
37+
this.title,
38+
this.drawer,
39+
this.floatingActionButton,
40+
this.tarWidgetControl})
2741
: super(key: key);
2842

2943
@override
30-
_GSYTabBarState createState() => new _GSYTabBarState(type, tabItems, tabViews, backgroundColor, indicatorColor, title, drawer);
44+
_GSYTabBarState createState() =>
45+
new _GSYTabBarState(type, tabItems, tabViews, backgroundColor, indicatorColor, title, drawer, floatingActionButton, tarWidgetControl);
3146
}
3247

3348
// ignore: mixin_inherits_from_not_object
@@ -46,7 +61,13 @@ class _GSYTabBarState extends State<GSYTabBarWidget> with SingleTickerProviderSt
4661

4762
final Widget _drawer;
4863

49-
_GSYTabBarState(this._type, this._tabItems, this._tabViews, this._backgroundColor, this._indicatorColor, this._title, this._drawer) : super();
64+
final Widget _floatingActionButton;
65+
66+
final TarWidgetControl tarWidgetControl;
67+
68+
_GSYTabBarState(this._type, this._tabItems, this._tabViews, this._backgroundColor, this._indicatorColor, this._title, this._drawer,
69+
this._floatingActionButton, this.tarWidgetControl)
70+
: super();
5071

5172
TabController _tabController;
5273

@@ -77,6 +98,8 @@ class _GSYTabBarState extends State<GSYTabBarWidget> with SingleTickerProviderSt
7798
return new DefaultTabController(
7899
length: _tabItems.length,
79100
child: new Scaffold(
101+
floatingActionButton: _floatingActionButton,
102+
persistentFooterButtons: tarWidgetControl == null ? [] : tarWidgetControl.footerButton,
80103
appBar: new AppBar(
81104
backgroundColor: _backgroundColor,
82105
title: new Text(_title),
@@ -97,7 +120,11 @@ class _GSYTabBarState extends State<GSYTabBarWidget> with SingleTickerProviderSt
97120
drawer: _drawer,
98121
appBar: new AppBar(
99122
backgroundColor: _backgroundColor,
100-
title: new Text(_title, maxLines: 1, overflow: TextOverflow.ellipsis,),
123+
title: new Text(
124+
_title,
125+
maxLines: 1,
126+
overflow: TextOverflow.ellipsis,
127+
),
101128
),
102129
body: new TabBarView(
103130
//TabBarView呈现内容,因此放到Scaffold的body中
@@ -115,3 +142,7 @@ class _GSYTabBarState extends State<GSYTabBarWidget> with SingleTickerProviderSt
115142
));
116143
}
117144
}
145+
146+
class TarWidgetControl {
147+
List<Widget> footerButton = [];
148+
}

0 commit comments

Comments
 (0)