Repository navigation
Expand file tree
/
Copy pathGSYTabBarWidget.dart
More file actions
163 lines (132 loc) · 3.93 KB
/
Copy pathGSYTabBarWidget.dart
File metadata and controls
163 lines (132 loc) · 3.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import 'package:flutter/material.dart';
///支持顶部和顶部的TabBar控件
///配合AutomaticKeepAliveClientMixin可以keep住
class GSYTabBarWidget extends StatefulWidget {
///底部模式type
static const int BOTTOM_TAB = 1;
///顶部模式type
static const int TOP_TAB = 2;
final int type;
final List<Widget> tabItems;
final List<Widget> tabViews;
final Color backgroundColor;
final Color indicatorColor;
final Widget title;
final Widget drawer;
final Widget floatingActionButton;
final TarWidgetControl tarWidgetControl;
final PageController topPageControl;
final ValueChanged<int> onPageChanged;
GSYTabBarWidget({
Key key,
this.type,
this.tabItems,
this.tabViews,
this.backgroundColor,
this.indicatorColor,
this.title,
this.drawer,
this.floatingActionButton,
this.tarWidgetControl,
this.topPageControl,
this.onPageChanged,
}) : super(key: key);
@override
_GSYTabBarState createState() => new _GSYTabBarState(
type,
tabViews,
indicatorColor,
title,
drawer,
floatingActionButton,
tarWidgetControl,
topPageControl,
onPageChanged,
);
}
// ignore: mixin_inherits_from_not_object
class _GSYTabBarState extends State<GSYTabBarWidget> with SingleTickerProviderStateMixin {
final int _type;
final List<Widget> _tabViews;
final Color _indicatorColor;
final Widget _title;
final Widget _drawer;
final Widget _floatingActionButton;
final TarWidgetControl _tarWidgetControl;
final PageController _pageController;
final ValueChanged<int> _onPageChanged;
_GSYTabBarState(
this._type,
this._tabViews,
this._indicatorColor,
this._title,
this._drawer,
this._floatingActionButton,
this._tarWidgetControl,
this._pageController,
this._onPageChanged,
) : super();
TabController _tabController;
@override
void initState() {
super.initState();
_tabController = new TabController(vsync: this, length: widget.tabItems.length);
}
///整个页面dispose时,记得把控制器也dispose掉,释放内存
@override
void dispose() {
_tabController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
if (this._type == GSYTabBarWidget.TOP_TAB) {
///顶部tab bar
return new Scaffold(
floatingActionButton: _floatingActionButton,
persistentFooterButtons: _tarWidgetControl == null ? [] : _tarWidgetControl.footerButton,
appBar: new AppBar(
backgroundColor: Theme.of(context).primaryColor,
title: _title,
bottom: new TabBar(
controller: _tabController,
tabs: widget.tabItems,
indicatorColor: _indicatorColor,
),
),
body: new PageView(
controller: _pageController,
children: _tabViews,
onPageChanged: (index) {
_tabController.animateTo(index);
_onPageChanged?.call(index);
},
),
);
}
///底部tab bar
return new Scaffold(
drawer: _drawer,
appBar: new AppBar(
backgroundColor: Theme.of(context).primaryColor,
title: _title,
),
body: new TabBarView(
//TabBarView呈现内容,因此放到Scaffold的body中
controller: _tabController, //配置控制器
children: _tabViews),
bottomNavigationBar: new Material(
//为了适配主题风格,包一层Material实现风格套用
color: Theme.of(context).primaryColor, //底部导航栏主题颜色
child: new TabBar(
//TabBar导航标签,底部导航放到Scaffold的bottomNavigationBar中
controller: _tabController, //配置控制器
tabs: widget.tabItems,
indicatorColor: _indicatorColor, //tab标签的下划线颜色
),
));
}
}
class TarWidgetControl {
List<Widget> footerButton = [];
}