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