X Tutup
Skip to content

Commit c0df93e

Browse files
committed
fix 通用item
1 parent 976b4b8 commit c0df93e

File tree

6 files changed

+143
-203
lines changed

6 files changed

+143
-203
lines changed

lib/page/RepositoryDetailIssueList.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart';
77
import 'package:gsy_github_app_flutter/widget/GSYListState.dart';
88
import 'package:gsy_github_app_flutter/widget/GSYPullLoadWidget.dart';
99
import 'package:gsy_github_app_flutter/widget/IssueItem.dart';
10-
import 'package:gsy_github_app_flutter/widget/RepositoryIssueListHeader.dart';
10+
import 'package:gsy_github_app_flutter/widget/GSYSelectItemWidget.dart';
1111

1212
/**
1313
* 仓库详情issue列表
@@ -83,7 +83,11 @@ class _RepositoryDetailIssuePageState extends GSYListState<RepositoryDetailIssue
8383
),
8484
elevation: 0.0,
8585
backgroundColor: Color(GSYColors.mainBackgroundColor),
86-
bottom: new RepositoryIssueListHeader((selectIndex) {}),
86+
bottom: new GSYSelectItemWidget([
87+
GSYStrings.repos_tab_issue_all,
88+
GSYStrings.repos_tab_issue_open,
89+
GSYStrings.repos_tab_issue_closed,
90+
], (selectIndex) {}),
8791
),
8892
body: GSYPullLoadWidget(
8993
pullLoadWidgetControl,
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart';
3+
import 'package:gsy_github_app_flutter/widget/GSYCardItem.dart';
4+
5+
/**
6+
* 详情issue列表头部,PreferredSizeWidget
7+
* Created by guoshuyu
8+
* Date: 2018-07-19
9+
*/
10+
11+
typedef void SelectItemChanged<int>(int value);
12+
13+
class GSYSelectItemWidget extends StatefulWidget implements PreferredSizeWidget {
14+
final List<String> itemNames;
15+
16+
final SelectItemChanged selectItemChanged;
17+
18+
GSYSelectItemWidget(this.itemNames, this.selectItemChanged);
19+
20+
@override
21+
_GSYSelectItemWidgetState createState() => _GSYSelectItemWidgetState(selectItemChanged, itemNames);
22+
23+
@override
24+
Size get preferredSize {
25+
return new Size.fromHeight(50.0);
26+
}
27+
}
28+
29+
class _GSYSelectItemWidgetState extends State<GSYSelectItemWidget> {
30+
int selectIndex = 0;
31+
32+
final List<String> itemNames;
33+
34+
final SelectItemChanged selectItemChanged;
35+
36+
_GSYSelectItemWidgetState(this.selectItemChanged, this.itemNames);
37+
38+
_renderItem(String name, int index) {
39+
var style = index == selectIndex ? GSYConstant.middleTextWhite : GSYConstant.middleSubText;
40+
return new Expanded(
41+
child: FlatButton(
42+
child: new Text(
43+
name,
44+
style: style,
45+
textAlign: TextAlign.center,
46+
),
47+
onPressed: () {
48+
setState(() {
49+
selectIndex = index;
50+
});
51+
if (selectItemChanged != null) {
52+
selectItemChanged(index);
53+
}
54+
}),
55+
);
56+
}
57+
58+
_renderList() {
59+
List<Widget> list = new List();
60+
for (int i = 0; i < itemNames.length; i++) {
61+
if (i == itemNames.length - 1) {
62+
list.add(_renderItem(itemNames[i], i));
63+
} else {
64+
list.add(_renderItem(itemNames[i], i));
65+
list.add(new Container(width: 1.0, height: 30.0, color: Color(GSYColors.subLightTextColor)));
66+
}
67+
}
68+
return list;
69+
}
70+
71+
@override
72+
Widget build(BuildContext context) {
73+
return new GSYCardItem(
74+
color: Color(GSYColors.primaryValue),
75+
margin: EdgeInsets.all(10.0),
76+
shape: new RoundedRectangleBorder(
77+
borderRadius: BorderRadius.all(Radius.circular(4.0)),
78+
),
79+
child: new Padding(
80+
padding: new EdgeInsets.only(left: 0.0, top: 5.0, right: 0.0, bottom: 5.0),
81+
child: new Row(
82+
children: _renderList(),
83+
)));
84+
}
85+
}

lib/widget/ReposHeaderItem.dart

Lines changed: 20 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,22 @@ class ReposHeaderItem extends StatelessWidget {
1414

1515
ReposHeaderItem(this.reposHeaderViewModel) : super();
1616

17+
_getBottomItem(IconData icon, String text) {
18+
return new Expanded(
19+
child: new Center(
20+
child: new GSYIConText(
21+
icon,
22+
text,
23+
GSYConstant.middleSubText,
24+
Color(GSYColors.subTextColor),
25+
15.0,
26+
padding: 3.0,
27+
mainAxisAlignment: MainAxisAlignment.center,
28+
),
29+
),
30+
);
31+
}
32+
1733
@override
1834
Widget build(BuildContext context) {
1935
String createStr = reposHeaderViewModel.repositoryIsFork
@@ -74,61 +90,10 @@ class ReposHeaderItem extends StatelessWidget {
7490
crossAxisAlignment: CrossAxisAlignment.center,
7591
mainAxisAlignment: MainAxisAlignment.center,
7692
children: <Widget>[
77-
new Expanded(
78-
child: new Center(
79-
child: new GSYIConText(
80-
GSYICons.REPOS_ITEM_STAR,
81-
reposHeaderViewModel.repositoryStar,
82-
GSYConstant.middleSubText,
83-
Color(GSYColors.subTextColor),
84-
15.0,
85-
padding: 3.0,
86-
mainAxisAlignment: MainAxisAlignment.center,
87-
),
88-
),
89-
),
90-
new Container(width: 0.3, height: 30.0, color: Color(GSYColors.subLightTextColor)),
91-
new Expanded(
92-
child: new Center(
93-
child: new GSYIConText(
94-
GSYICons.REPOS_ITEM_FORK,
95-
reposHeaderViewModel.repositoryFork,
96-
GSYConstant.middleSubText,
97-
Color(GSYColors.subTextColor),
98-
15.0,
99-
padding: 3.0,
100-
mainAxisAlignment: MainAxisAlignment.center,
101-
),
102-
),
103-
),
104-
new Container(width: 0.3, height: 30.0, color: Color(GSYColors.subLightTextColor)),
105-
new Expanded(
106-
child: new Center(
107-
child: new GSYIConText(
108-
GSYICons.REPOS_ITEM_ISSUE,
109-
reposHeaderViewModel.repositoryWatch,
110-
GSYConstant.middleSubText,
111-
Color(GSYColors.subTextColor),
112-
15.0,
113-
padding: 3.0,
114-
mainAxisAlignment: MainAxisAlignment.center,
115-
),
116-
),
117-
),
118-
new Container(width: 0.3, height: 30.0, color: Color(GSYColors.subLightTextColor)),
119-
new Expanded(
120-
child: new Center(
121-
child: new GSYIConText(
122-
GSYICons.REPOS_ITEM_ISSUE,
123-
reposHeaderViewModel.repositoryIssue,
124-
GSYConstant.middleSubText,
125-
Color(GSYColors.subTextColor),
126-
15.0,
127-
padding: 3.0,
128-
mainAxisAlignment: MainAxisAlignment.center,
129-
),
130-
),
131-
),
93+
_getBottomItem(GSYICons.REPOS_ITEM_STAR, reposHeaderViewModel.repositoryStar),
94+
_getBottomItem(GSYICons.REPOS_ITEM_FORK, reposHeaderViewModel.repositoryFork),
95+
_getBottomItem(GSYICons.REPOS_ITEM_WATCH, reposHeaderViewModel.repositoryWatch),
96+
_getBottomItem(GSYICons.REPOS_ITEM_ISSUE, reposHeaderViewModel.repositoryIssue),
13297
],
13398
)),
13499
],

lib/widget/ReposItem.dart

Lines changed: 19 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,22 @@ class ReposItem extends StatelessWidget {
1515

1616
ReposItem(this.reposViewModel, {this.onPressed}) : super();
1717

18+
_getBottomItem(IconData icon, String text, {int flex = 2}) {
19+
return new Expanded(
20+
flex: flex,
21+
child: new Center(
22+
child: new GSYIConText(
23+
icon,
24+
text,
25+
GSYConstant.subSmallText,
26+
Color(GSYColors.subTextColor),
27+
15.0,
28+
padding: 5.0,
29+
),
30+
),
31+
);
32+
}
33+
1834
@override
1935
Widget build(BuildContext context) {
2036
return new Container(
@@ -72,43 +88,9 @@ class ReposItem extends StatelessWidget {
7288
new Row(
7389
crossAxisAlignment: CrossAxisAlignment.start,
7490
children: <Widget>[
75-
new Expanded(
76-
child: new Center(
77-
child: new GSYIConText(
78-
GSYICons.REPOS_ITEM_STAR,
79-
reposViewModel.repositoryStar,
80-
GSYConstant.subSmallText,
81-
Color(GSYColors.subTextColor),
82-
15.0,
83-
padding: 5.0,
84-
),
85-
),
86-
),
87-
new Expanded(
88-
child: new Center(
89-
child: new GSYIConText(
90-
GSYICons.REPOS_ITEM_FORK,
91-
reposViewModel.repositoryFork,
92-
GSYConstant.subSmallText,
93-
Color(GSYColors.subTextColor),
94-
15.0,
95-
padding: 5.0,
96-
),
97-
),
98-
),
99-
new Expanded(
100-
flex: 2,
101-
child: new Center(
102-
child: new GSYIConText(
103-
GSYICons.REPOS_ITEM_ISSUE,
104-
reposViewModel.repositoryWatch,
105-
GSYConstant.subSmallText,
106-
Color(GSYColors.subTextColor),
107-
15.0,
108-
padding: 5.0,
109-
),
110-
),
111-
),
91+
_getBottomItem(GSYICons.REPOS_ITEM_STAR, reposViewModel.repositoryStar),
92+
_getBottomItem(GSYICons.REPOS_ITEM_FORK, reposViewModel.repositoryFork),
93+
_getBottomItem(GSYICons.REPOS_ITEM_ISSUE, reposViewModel.repositoryWatch, flex: 4),
11294
],
11395
),
11496
],

lib/widget/RepositoryIssueListHeader.dart

Lines changed: 0 additions & 81 deletions
This file was deleted.

0 commit comments

Comments
 (0)
X Tutup