-
Notifications
You must be signed in to change notification settings - Fork 121
/
Copy pathtd_tabs_page.dart
445 lines (418 loc) · 11.4 KB
/
td_tabs_page.dart
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
import 'package:flutter/material.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';
import '../../base/example_widget.dart';
import '../annotation/demo.dart';
class TDTabsPage extends StatefulWidget {
const TDTabsPage({Key? key}) : super(key: key);
@override
State<StatefulWidget> createState() => _TDTabsPageState();
}
class _TDTabsPageState extends State<TDTabsPage>
with TickerProviderStateMixin {
TabController? _tabController1;
TabController? _tabController2;
TabController? _tabController3;
TabController? _tabController4;
List<TDTab> tabs = [];
List<Widget> tabViews = [];
List<TDTab> _getTabs() {
tabs = const [
TDTab(
text: '选项',
),
TDTab(
text: '选项',
),
TDTab(text: '选项'),
TDTab(text: '选项'),
TDTab(text: '选项'),
TDTab(text: '选项'),
TDTab(text: '选项'),
TDTab(text: '选项'),
TDTab(text: '选项'),
TDTab(text: '选项'),
TDTab(text: '选项'),
TDTab(text: '选项'),
TDTab(text: '选项'),
TDTab(text: '选项'),
TDTab(text: '选项'),
TDTab(text: '选项'),
TDTab(text: '选项'),
TDTab(text: '选项'),
TDTab(text: '选项'),
TDTab(text: '选项'),
TDTab(text: '选项'),
];
return tabs;
}
List<Widget> _getTabViews() {
tabViews = const [
Center(child: TDText('内容区')),
Center(child: TDText('内容区')),
Center(child: TDText('内容区')),
];
return tabViews;
}
@override
void initState() {
_initTabController();
_getTabs();
super.initState();
}
List<TDTab> subList(int length) {
var temp = <TDTab>[];
for (var i = 0; i < length; i++) {
temp.add(tabs[i]);
}
switch (length) {
case 3:
temp[temp.length - 1] = const TDTab(text: '上限六个字');
break;
case 4:
temp[temp.length - 1] = const TDTab(text: '上限四字');
break;
case 5:
temp[temp.length - 1] = const TDTab(text: '上限三');
break;
}
return temp;
}
//初始化tab
void _initTabController() {
_tabController1 = TabController(length: 2, vsync: this);
_tabController2 = TabController(length: 3, vsync: this);
_tabController3 = TabController(length: 4, vsync: this);
_tabController4 = TabController(length: 5, vsync: this);
}
@override
Widget build(BuildContext context) {
return ExamplePage(
title: tdTitle(),
desc: '用于内容分类后的展示切换。',
exampleCodeGroup: 'tabs',
children: [
ExampleModule(
title: '组件类型',
children: [
ExampleItem(desc: '均分选项卡', builder: _buildItemWithSplit1),
ExampleItem(builder: _buildItemWithSplit2, padding: const EdgeInsets.only(top: 16)),
ExampleItem(builder: _buildItemWithSplit3, padding: const EdgeInsets.only(top: 16)),
ExampleItem(builder: _buildItemWithSplit4, padding: const EdgeInsets.only(top: 16)),
ExampleItem(desc: '等距选项卡', builder: _buildItemWithSpace),
ExampleItem(desc: '带图标选项卡', builder: _buildItemWithIcon),
ExampleItem(desc: '带微标选项卡', builder: _buildItemWithLogo),
ExampleItem(desc: '带内容区选项卡', builder: _buildItemWithContent),
],
),
ExampleModule(title: '组件状态', children: [
ExampleItem(desc: '选项卡状态', builder: _buildItemWithStatus),
]),
ExampleModule(title: '组件样式', children: [
ExampleItem(desc: '选项卡尺寸', builder: _buildItemWithSizeSmall),
ExampleItem(builder: _buildItemWithSizeBig, padding: const EdgeInsets.only(top: 16)),
ExampleItem(desc: '选项卡样式', builder: _buildItemWithOutlineNormal),
ExampleItem(builder: _buildItemWithOutlineCard, padding: const EdgeInsets.only(top: 16)),
]),
],
test: [
ExampleItem(desc: '自定义下标属性', builder: _customIndicatorStyle),
ExampleItem(desc: '自定义下划线样式', builder: _customDividerStyle),
ExampleItem(desc: '不展示下划线-高度为0', builder: _hideBottomDivider),
ExampleItem(desc: 'capsule类型可修改背景色', builder: _capsuleBackgroundColor),
],);
}
@Demo(group: 'tabs')
Widget _buildItemWithSplit1(BuildContext context) {
return TDTabBar(
tabs: subList(2),
controller: _tabController1,
backgroundColor: Colors.white,
showIndicator: true,
);
}
@Demo(group: 'tabs')
Widget _buildItemWithSplit2(BuildContext context) {
return TDTabBar(
tabs: subList(3),
controller: _tabController2,
backgroundColor: Colors.white,
showIndicator: true,
);
}
@Demo(group: 'tabs')
Widget _buildItemWithSplit3(BuildContext context) {
return TDTabBar(
tabs: subList(4),
controller: _tabController3,
backgroundColor: Colors.white,
showIndicator: true,
);
}
@Demo(group: 'tabs')
Widget _buildItemWithSplit4(BuildContext context) {
return TDTabBar(
tabs: subList(5),
controller: _tabController4,
backgroundColor: Colors.white,
showIndicator: true,
);
}
@Demo(group: 'tabs')
Widget _buildItemWithSpace(BuildContext context) {
return TDTabBar(
tabs: subList(16),
controller: TabController(length: 16, vsync: this),
backgroundColor: Colors.white,
labelPadding: const EdgeInsets.all(10),
showIndicator: true,
isScrollable: true,
);
}
@Demo(group: 'tabs')
Widget _buildItemWithIcon(BuildContext context) {
var tabs = [
const TDTab(
text: '选项',
icon: Icon(
TDIcons.app,
size: 18,
),
),
const TDTab(
text: '选项',
icon: Icon(
TDIcons.app,
size: 18,
),
),
const TDTab(
text: '选项',
icon: Icon(
TDIcons.app,
size: 18,
),
),
];
return TDTabBar(
tabs: tabs,
controller: TabController(length: 3, vsync: this),
backgroundColor: Colors.white,
showIndicator: true);
}
@Demo(group: 'tabs')
Widget _buildItemWithLogo(BuildContext context) {
var tabs = [
const TDTab(
text: '选项',
contentHeight: 48,
textMargin: EdgeInsets.only(right: 8),
badge: TDBadge(TDBadgeType.redPoint),
),
const TDTab(
text: '选项',
contentHeight: 42,
textMargin: EdgeInsets.only(right: 16, top: 2, bottom: 2),
badge: TDBadge(
TDBadgeType.message,
message: '8',
),
),
const TDTab(
text: '选项',
height: 48,
icon: Icon(
TDIcons.app,
size: 18,
),
),
];
return TDTabBar(
tabs: tabs,
controller: TabController(length: 3, vsync: this),
backgroundColor: Colors.white,
showIndicator: true);
}
@Demo(group: 'tabs')
Widget _buildItemWithContent(BuildContext context) {
var tabController = TabController(length: 3, vsync: this);
return SizedBox(
height: 120 + 48,
child: Column(
children: [
TDTabBar(
tabs: subList(3),
controller: tabController,
showIndicator: true,
backgroundColor: Colors.white,
isScrollable: false,),
Container(
height: 120,
color: Colors.white,
child: TDTabBarView(
children: _getTabViews(),
controller: tabController,
),
)
],
),
);
}
@Demo(group: 'tabs')
Widget _buildItemWithStatus(BuildContext context) {
var tabs = [
const TDTab(
text: '选中',
),
const TDTab(
text: '默认',
),
const TDTab(
text: '禁用',
enable: false,
),
];
return TDTabBar(
tabs: tabs,
controller: TabController(length: 3, vsync: this),
backgroundColor: Colors.white,
showIndicator: true);
}
@Demo(group: 'tabs')
Widget _buildItemWithSizeSmall(BuildContext context) {
var tabs = [
const TDTab(
text: '小尺寸',
),
const TDTab(
text: '选项',
),
const TDTab(
text: '选项',
),
const TDTab(
text: '选项',
),
];
return TDTabBar(
tabs: tabs,
controller: TabController(length: 4, vsync: this),
backgroundColor: Colors.white,
showIndicator: true);
}
@Demo(group: 'tabs')
Widget _buildItemWithSizeBig(BuildContext context) {
var tabs = [
const TDTab(
text: '大尺寸',
size: TDTabSize.large,
),
const TDTab(
text: '选项',
size: TDTabSize.large,
),
const TDTab(
text: '选项',
size: TDTabSize.large,
),
const TDTab(
text: '选项',
size: TDTabSize.large,
),
];
return TDTabBar(
tabs: tabs,
controller: TabController(length: 4, vsync: this),
backgroundColor: Colors.white,
showIndicator: true);
}
@Demo(group: 'tabs')
Widget _buildItemWithOutlineNormal(BuildContext context) {
var tabs = [
const TDTab(
text: '选项',
),
const TDTab(
text: '选项',
),
const TDTab(
text: '选项',
),
const TDTab(
text: '选项',
),
];
return TDTabBar(
tabs: tabs,
outlineType: TDTabBarOutlineType.capsule,
controller: TabController(length: 4, vsync: this),
backgroundColor: Colors.white,
showIndicator: false);
}
@Demo(group: 'tabs')
Widget _buildItemWithOutlineCard(BuildContext context) {
var tabs = [
const TDTab(
text: '选项',
),
const TDTab(
text: '选项',
),
const TDTab(
text: '选项',
),
const TDTab(
text: '选项',
),
];
return TDTabBar(
tabs: tabs,
outlineType: TDTabBarOutlineType.card,
controller: TabController(length: 4, vsync: this),
backgroundColor: Colors.white,
showIndicator: false);
}
@Demo(group: 'tabs')
Widget _customIndicatorStyle(BuildContext context) {
return TDTabBar(
tabs: subList(2),
controller: _tabController1,
backgroundColor: Colors.white,
showIndicator: true,
indicatorColor: Colors.red,
indicatorHeight: 20,
indicatorWidth: 10,
indicatorPadding: const EdgeInsets.only(left: 20),
);
}
@Demo(group: 'tabs')
Widget _customDividerStyle(BuildContext context) {
return TDTabBar(
tabs: subList(2),
controller: _tabController1,
backgroundColor: Colors.white,
showIndicator: true,
dividerColor: Colors.red,
dividerHeight: 5,
);
}
@Demo(group: 'tabs')
Widget _hideBottomDivider(BuildContext context) {
return TDTabBar(
tabs: subList(2),
controller: _tabController1,
backgroundColor: Colors.white,
showIndicator: true,
dividerColor: Colors.red,
dividerHeight: 0,
);
}
@Demo(group: 'tabs')
Widget _capsuleBackgroundColor(BuildContext context) {
return TDTabBar(
tabs: subList(2),
controller: _tabController1,
backgroundColor: Colors.red,
outlineType: TDTabBarOutlineType.capsule,
);
}
}