This repository has been archived by the owner on Dec 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathaqua_tab_bar.dart
154 lines (138 loc) · 5.04 KB
/
aqua_tab_bar.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
import "package:aqua/src/common_widgets/aqua_theme.dart";
import "package:flutter/widgets.dart";
class AquaTabBar extends StatefulWidget {
AquaTabBar({
Key? key,
required this.items,
this.initialSelectedIndex = 0,
this.activeIndex = 0,
this.onChanged,
}) : super(key: key);
final List<AquaTabBarItem> items;
final int initialSelectedIndex;
final int activeIndex;
final void Function(int index)? onChanged;
@override
_AquaTabBarState createState() => _AquaTabBarState();
}
class _AquaTabBarState extends State<AquaTabBar> {
late int _selectedIndex;
@override
void initState() {
super.initState();
_selectedIndex = widget.activeIndex;
}
@override
void didUpdateWidget(AquaTabBar oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.activeIndex != oldWidget.activeIndex) {
_selectedIndex = widget.activeIndex;
}
}
@override
Widget build(BuildContext context) {
return DecoratedBox(
decoration: BoxDecoration(
color: AquaTheme.of(context).scaffoldStyle.backgroundColor,
boxShadow: AquaTheme.of(context)
.elevationBoxShadows
.map((boxShadow) => BoxShadow(
color: boxShadow.color,
offset: boxShadow.offset * -1,
blurRadius: boxShadow.blurRadius,
spreadRadius: boxShadow.spreadRadius,
))
.toList(),
),
child: SafeArea(
top: false,
bottom: true,
child: LayoutBuilder(builder: (context, constraints) {
return Stack(
children: [
Row(
mainAxisSize: MainAxisSize.max,
children: List.generate(widget.items.length, (index) {
return Expanded(
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
setState(() {
_selectedIndex = index;
});
if (widget.onChanged != null) {
widget.onChanged!(index);
}
},
child: Padding(
padding: EdgeInsets.only(top: 8, bottom: 4),
child: Column(
children: [
TweenAnimationBuilder<Color?>(
tween: ColorTween(
begin: AquaTheme.of(context)
.textStyleSet
.caption
.color,
end: _selectedIndex == index
? AquaTheme.of(context).cursorColor
: AquaTheme.of(context)
.textStyleSet
.caption
.color,
),
duration: Duration(milliseconds: 200),
builder: (context, color, _) => Icon(
widget.items[index].icon,
size: 24,
color: color,
),
),
TweenAnimationBuilder<TextStyle>(
tween: TextStyleTween(
begin: AquaTheme.of(context)
.textStyleSet
.caption
.copyWith(fontSize: 10),
end: AquaTheme.of(context)
.textStyleSet
.caption
.copyWith(
color: _selectedIndex == index
? AquaTheme.of(context).cursorColor
: AquaTheme.of(context)
.textStyleSet
.caption
.color,
fontSize: 10,
),
),
duration: Duration(milliseconds: 200),
builder: (context, style, _) => Text(
widget.items[index].label,
style: style,
),
),
],
),
),
),
);
}),
),
],
);
}),
),
);
}
}
@immutable
class AquaTabBarItem {
const AquaTabBarItem({
required this.label,
required this.icon,
});
final String label;
final IconData icon;
}