X Tutup
Skip to content

Commit c376275

Browse files
committed
change tabview to pageview
1 parent 8293f72 commit c376275

File tree

4 files changed

+86
-46
lines changed

4 files changed

+86
-46
lines changed

RECORD.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ https://github.com/flutter/flutter/issues/11895 tab alive
3636

3737
https://github.com/flutter/flutter/issues/19030 没有webview,残念
3838

39+
_debugUltimatePreviousSiblingOf
3940

4041
GlobalKey可以记录state,但是需要跟随build创建
4142

lib/page/RepositoryDetailPage.dart

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ class _RepositoryDetailPageState extends State<RepositoryDetailPage> {
4646

4747
final BranchControl branchControl = new BranchControl("master");
4848

49+
final PageController topPageControl = new PageController();
50+
4951
GlobalKey<RepositoryDetailFileListPageState> fileListKey = new GlobalKey<RepositoryDetailFileListPageState>();
5052

5153
GlobalKey<ReposDetailInfoPageState> infoListKey = new GlobalKey<ReposDetailInfoPageState>();
@@ -217,24 +219,54 @@ class _RepositoryDetailPageState extends State<RepositoryDetailPage> {
217219
_getBranchList();
218220
}
219221

220-
221222
@override
222223
Widget build(BuildContext context) {
223224
return new GSYTabBarWidget(
224225
type: GSYTabBarWidget.TOP_TAB,
225226
tarWidgetControl: tarBarControl,
226227
tabItems: [
227-
new Tab(text: GSYStrings.repos_tab_info),
228-
new Tab(text: GSYStrings.repos_tab_readme),
229-
new Tab(text: GSYStrings.repos_tab_issue),
230-
new Tab(text: GSYStrings.repos_tab_file),
228+
///无奈之举,只能pageView配合tabbar,通过control同步
229+
///TabView 配合tabbar 在四个页面上问题太多
230+
new FlatButton(
231+
onPressed: () {
232+
topPageControl.jumpTo(0.0);
233+
},
234+
child: new Text(
235+
GSYStrings.repos_tab_info,
236+
style: GSYConstant.smallTextWhite,
237+
)),
238+
new FlatButton(
239+
onPressed: () {
240+
topPageControl.jumpTo(MediaQuery.of(context).size.width);
241+
},
242+
child: new Text(
243+
GSYStrings.repos_tab_readme,
244+
style: GSYConstant.smallTextWhite,
245+
)),
246+
new FlatButton(
247+
onPressed: () {
248+
topPageControl.jumpTo(MediaQuery.of(context).size.width * 2);
249+
},
250+
child: new Text(
251+
GSYStrings.repos_tab_issue,
252+
style: GSYConstant.smallTextWhite,
253+
)),
254+
new FlatButton(
255+
onPressed: () {
256+
topPageControl.jumpTo(MediaQuery.of(context).size.width * 3);
257+
},
258+
child: new Text(
259+
GSYStrings.repos_tab_file,
260+
style: GSYConstant.smallTextWhite,
261+
)),
231262
],
232263
tabViews: [
233264
new ReposDetailInfoPage(reposDetailInfoPageControl, userName, reposName, branchControl),
234265
new RepositoryDetailReadmePage(userName, reposName, branchControl),
235266
new RepositoryDetailIssuePage(userName, reposName),
236267
new RepositoryDetailFileListPage(userName, reposName, branchControl),
237268
],
269+
topPageControl: topPageControl,
238270
backgroundColor: GSYColors.primarySwatch,
239271
indicatorColor: Colors.white,
240272
title: new GSYTitleBar(reposName));

lib/widget/GSYSelectItemWidget.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class GSYSelectItemWidget extends StatefulWidget implements PreferredSizeWidget
2525
this.itemNames,
2626
this.selectItemChanged, {
2727
this.elevation = 5.0,
28-
this.height = 50.0,
28+
this.height = 70.0,
2929
this.margin = const EdgeInsets.all(10.0),
3030
});
3131

lib/widget/GSYTabBarWidget.dart

Lines changed: 47 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,25 @@ class GSYTabBarWidget extends StatefulWidget {
2727

2828
final TarWidgetControl tarWidgetControl;
2929

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})
41-
: super(key: key);
30+
final PageController topPageControl;
31+
32+
GSYTabBarWidget({
33+
Key key,
34+
this.type,
35+
this.tabItems,
36+
this.tabViews,
37+
this.backgroundColor,
38+
this.indicatorColor,
39+
this.title,
40+
this.drawer,
41+
this.floatingActionButton,
42+
this.tarWidgetControl,
43+
this.topPageControl,
44+
}) : super(key: key);
4245

4346
@override
44-
_GSYTabBarState createState() =>
45-
new _GSYTabBarState(type, tabItems, tabViews, backgroundColor, indicatorColor, title, drawer, floatingActionButton, tarWidgetControl);
47+
_GSYTabBarState createState() => new _GSYTabBarState(
48+
type, tabItems, tabViews, backgroundColor, indicatorColor, title, drawer, floatingActionButton, tarWidgetControl, topPageControl);
4649
}
4750

4851
// ignore: mixin_inherits_from_not_object
@@ -63,55 +66,59 @@ class _GSYTabBarState extends State<GSYTabBarWidget> with SingleTickerProviderSt
6366

6467
final Widget _floatingActionButton;
6568

66-
final TarWidgetControl tarWidgetControl;
69+
final TarWidgetControl _tarWidgetControl;
70+
71+
final PageController _pageController;
6772

6873
_GSYTabBarState(this._type, this._tabItems, this._tabViews, this._backgroundColor, this._indicatorColor, this._title, this._drawer,
69-
this._floatingActionButton, this.tarWidgetControl)
74+
this._floatingActionButton, this._tarWidgetControl, this._pageController)
7075
: super();
7176

7277
TabController _tabController;
7378

7479
@override
7580
void initState() {
7681
super.initState();
77-
if (this._type == GSYTabBarWidget.BOTTOM_TAB) {
78-
_tabController = new TabController(
79-
vsync: this, //动画效果的异步处理,默认格式,背下来即可
80-
length: _tabItems.length //需要控制的Tab页数量
81-
);
82-
}
82+
//if (this._type == GSYTabBarWidget.BOTTOM_TAB) {
83+
_tabController = new TabController(
84+
vsync: this, //动画效果的异步处理,默认格式,背下来即可
85+
length: _tabItems.length //需要控制的Tab页数量
86+
);
87+
//}
8388
}
8489

8590
///整个页面dispose时,记得把控制器也dispose掉,释放内存
8691
@override
8792
void dispose() {
88-
if (this._type == GSYTabBarWidget.BOTTOM_TAB) {
89-
_tabController.dispose();
90-
}
93+
//if (this._type == GSYTabBarWidget.BOTTOM_TAB) {
94+
_tabController.dispose();
95+
//}
9196
super.dispose();
9297
}
9398

9499
@override
95100
Widget build(BuildContext context) {
96101
if (this._type == GSYTabBarWidget.TOP_TAB) {
97102
///顶部tab bar
98-
return new DefaultTabController(
99-
length: _tabItems.length,
100-
child: new Scaffold(
101-
floatingActionButton: _floatingActionButton,
102-
persistentFooterButtons: tarWidgetControl == null ? [] : tarWidgetControl.footerButton,
103-
appBar: new AppBar(
104-
backgroundColor: _backgroundColor,
105-
title: _title,
106-
bottom: new TabBar(
107-
tabs: _tabItems,
108-
indicatorColor: _indicatorColor,
109-
),
110-
),
111-
body: new TabBarView(
112-
children: _tabViews,
103+
return new Scaffold(
104+
floatingActionButton: _floatingActionButton,
105+
persistentFooterButtons: _tarWidgetControl == null ? [] : _tarWidgetControl.footerButton,
106+
appBar: new AppBar(
107+
backgroundColor: _backgroundColor,
108+
title: _title,
109+
bottom: new TabBar(
110+
controller: _tabController,
111+
tabs: _tabItems,
112+
indicatorColor: _indicatorColor,
113113
),
114114
),
115+
body: new PageView(
116+
controller: _pageController,
117+
children: _tabViews,
118+
onPageChanged: (index) {
119+
_tabController.animateTo(index);
120+
},
121+
),
115122
);
116123
}
117124

0 commit comments

Comments
 (0)
X Tutup