@@ -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