@@ -47,13 +47,50 @@ class GSYTabBarWidget extends StatefulWidget {
4747 }) : super (key: key);
4848
4949 @override
50- _GSYTabBarState createState () => new _GSYTabBarState ();
50+ _GSYTabBarState createState () => new _GSYTabBarState (
51+ type,
52+ tabViews,
53+ indicatorColor,
54+ title,
55+ drawer,
56+ floatingActionButton,
57+ tarWidgetControl,
58+ topPageControl,
59+ onPageChanged,
60+ );
5161}
5262
5363// ignore: mixin_inherits_from_not_object
5464class _GSYTabBarState extends State <GSYTabBarWidget > with SingleTickerProviderStateMixin {
65+ final int _type;
5566
56- _GSYTabBarState ();
67+ final List <Widget > _tabViews;
68+
69+ final Color _indicatorColor;
70+
71+ final Widget _title;
72+
73+ final Widget _drawer;
74+
75+ final Widget _floatingActionButton;
76+
77+ final TarWidgetControl _tarWidgetControl;
78+
79+ final PageController _pageController;
80+
81+ final ValueChanged <int > _onPageChanged;
82+
83+ _GSYTabBarState (
84+ this ._type,
85+ this ._tabViews,
86+ this ._indicatorColor,
87+ this ._title,
88+ this ._drawer,
89+ this ._floatingActionButton,
90+ this ._tarWidgetControl,
91+ this ._pageController,
92+ this ._onPageChanged,
93+ ) : super ();
5794
5895 TabController _tabController;
5996
@@ -72,50 +109,50 @@ class _GSYTabBarState extends State<GSYTabBarWidget> with SingleTickerProviderSt
72109
73110 @override
74111 Widget build (BuildContext context) {
75- if (widget.type == GSYTabBarWidget .TOP_TAB ) {
112+ if (this ._type == GSYTabBarWidget .TOP_TAB ) {
76113 ///顶部tab bar
77114 return new Scaffold (
78- floatingActionButton: widget.floatingActionButton ,
79- persistentFooterButtons: widget.tarWidgetControl == null ? [] : widget.tarWidgetControl .footerButton,
115+ floatingActionButton: _floatingActionButton ,
116+ persistentFooterButtons: _tarWidgetControl == null ? [] : _tarWidgetControl .footerButton,
80117 appBar: new AppBar (
81118 backgroundColor: Theme .of (context).primaryColor,
82- title: widget.title ,
119+ title: _title ,
83120 bottom: new TabBar (
84121 controller: _tabController,
85122 tabs: widget.tabItems,
86- indicatorColor: widget.indicatorColor ,
123+ indicatorColor: _indicatorColor ,
87124 ),
88125 ),
89126 body: new PageView (
90- controller: widget.topPageControl ,
91- children: widget.tabViews ,
127+ controller: _pageController ,
128+ children: _tabViews ,
92129 onPageChanged: (index) {
93130 _tabController.animateTo (index);
94- widget.onPageChanged ? .call (index);
131+ _onPageChanged ? .call (index);
95132 },
96133 ),
97134 );
98135 }
99136
100137 ///底部tab bar
101138 return new Scaffold (
102- drawer: widget.drawer ,
139+ drawer: _drawer ,
103140 appBar: new AppBar (
104141 backgroundColor: Theme .of (context).primaryColor,
105- title: widget.title ,
142+ title: _title ,
106143 ),
107144 body: new TabBarView (
108- //TabBarView呈现内容,因此放到Scaffold的body中
145+ //TabBarView呈现内容,因此放到Scaffold的body中
109146 controller: _tabController, //配置控制器
110- children: widget.tabViews ),
147+ children: _tabViews ),
111148 bottomNavigationBar: new Material (
112149 //为了适配主题风格,包一层Material实现风格套用
113150 color: Theme .of (context).primaryColor, //底部导航栏主题颜色
114151 child: new TabBar (
115152 //TabBar导航标签,底部导航放到Scaffold的bottomNavigationBar中
116153 controller: _tabController, //配置控制器
117154 tabs: widget.tabItems,
118- indicatorColor: widget.indicatorColor , //tab标签的下划线颜色
155+ indicatorColor: _indicatorColor , //tab标签的下划线颜色
119156 ),
120157 ));
121158 }
0 commit comments