Line data Source code
1 : import 'package:flutter/cupertino.dart';
2 :
3 : import '../bar.dart';
4 : import '../interface.dart';
5 : import '../item.dart';
6 : import 'fixed_circle_tab_style.dart';
7 : import 'fixed_tab_style.dart';
8 : import 'flip_tab_style.dart';
9 : import 'react_circle_tab_style.dart';
10 : import 'react_tab_style.dart';
11 : import 'textin_tab_style.dart';
12 : import 'titled_tab_style.dart';
13 :
14 : /// Factory method to return the [DelegateBuilder] for each [TabStyle].
15 1 : DelegateBuilder supportedStyle(
16 : TabStyle style, {
17 : @required List<TabItem> items,
18 : Color color,
19 : Color activeColor,
20 : Color backgroundColor,
21 : Curve curve,
22 : }) {
23 1 : assert(items != null && items.isNotEmpty, 'items should not be empty');
24 : assert(
25 2 : ((style == TabStyle.fixed || style == TabStyle.fixedCircle) &&
26 2 : items.length.isOdd) ||
27 2 : (style != TabStyle.fixed && style != TabStyle.fixedCircle),
28 : 'item count should be an odd number when using fixed/fixedCircle');
29 : DelegateBuilder builder;
30 : switch (style) {
31 1 : case TabStyle.fixed:
32 1 : builder = FixedTabStyle(
33 : items: items,
34 : color: color,
35 : activeColor: activeColor,
36 2 : convexIndex: items.length ~/ 2,
37 : );
38 : break;
39 1 : case TabStyle.fixedCircle:
40 1 : builder = FixedCircleTabStyle(
41 : items: items,
42 : color: color,
43 : activeColor: activeColor,
44 : backgroundColor: backgroundColor,
45 2 : convexIndex: items.length ~/ 2,
46 : );
47 : break;
48 1 : case TabStyle.react:
49 1 : builder = ReactTabStyle(
50 : items: items,
51 : color: color,
52 : activeColor: activeColor,
53 : curve: curve,
54 : );
55 : break;
56 1 : case TabStyle.reactCircle:
57 1 : builder = ReactCircleTabStyle(
58 : items: items,
59 : color: color,
60 : activeColor: activeColor,
61 : backgroundColor: backgroundColor,
62 : curve: curve,
63 : );
64 : break;
65 1 : case TabStyle.textIn:
66 1 : builder = TextInTabStyle(
67 : items: items,
68 : color: color,
69 : activeColor: activeColor,
70 : curve: curve,
71 : );
72 : break;
73 1 : case TabStyle.titled:
74 1 : builder = TitledTabStyle(
75 : items: items,
76 : color: color,
77 : activeColor: activeColor,
78 : curve: curve,
79 : backgroundColor: backgroundColor,
80 : );
81 : break;
82 1 : case TabStyle.flip:
83 1 : builder = FlipTabStyle(
84 : items: items,
85 : color: color,
86 : activeColor: activeColor,
87 : curve: curve,
88 : );
89 : break;
90 : default:
91 0 : builder = ReactCircleTabStyle(
92 : items: items,
93 : color: color,
94 : activeColor: activeColor,
95 : backgroundColor: backgroundColor,
96 : curve: curve,
97 : );
98 : break;
99 : }
100 : return builder;
101 : }
|