-
-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathanimated_icon.dart
213 lines (197 loc) · 6.62 KB
/
animated_icon.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
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_widget_guide/utils.dart';
import '../Ads.dart';
import '../Code.dart';
import '../CodeScreen.dart';
class AnimatedIconWidget extends StatefulWidget {
@override
_AnimatedIconWidgetState createState() => _AnimatedIconWidgetState();
}
class _AnimatedIconWidgetState extends State<AnimatedIconWidget>
with TickerProviderStateMixin {
AnimationController _controller1;
String speedFabText = "Slowly";
@override
void initState() {
super.initState();
_controller1 = AnimationController(
duration: const Duration(seconds: 2),
vsync: this,
);
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
//Hide banner ad if it isn't already hidden
Ads.hideBannerAd();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
centerTitle: true,
title: Text(
'AnimatedIcon Widget',
style: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
fontFamily: Utils.ubuntuRegularFont),
),
actions: <Widget>[
IconButton(
icon: Icon(Icons.code),
onPressed: () => Navigator.push(
context,
MaterialPageRoute(
builder: (context) => CodeScreen(code: Code.animatedIconCode),
),
),
)
],
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
/// First row
Padding(
padding: const EdgeInsets.all(24.0),
child: animatedIconRow(_controller1, AnimatedIcons.add_event,
AnimatedIcons.arrow_menu, AnimatedIcons.close_menu),
),
/// Second row
Padding(
padding: const EdgeInsets.all(24.0),
child: animatedIconRow(
_controller1,
AnimatedIcons.ellipsis_search,
AnimatedIcons.event_add,
AnimatedIcons.home_menu),
),
/// Third row
Padding(
padding: const EdgeInsets.all(24.0),
child: animatedIconRow(_controller1, AnimatedIcons.list_view,
AnimatedIcons.menu_arrow, AnimatedIcons.menu_close),
),
/// Fourth row
Padding(
padding: const EdgeInsets.all(24.0),
child: animatedIconRow(_controller1, AnimatedIcons.menu_home,
AnimatedIcons.pause_play, AnimatedIcons.play_pause),
),
/// Fifth row
Padding(
padding: const EdgeInsets.all(24.0),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
AnimatedIcon(
size: 34.0,
icon: AnimatedIcons.search_ellipsis,
progress: _controller1,
),
AnimatedIcon(
size: 34.0,
icon: AnimatedIcons.view_list,
progress: _controller1,
),
],
),
),
Stack(
children: <Widget>[
Align(
alignment: Alignment.bottomLeft,
child: Padding(
padding: const EdgeInsets.only(left: 24.0),
/// Fab to control animation direction
child: FloatingActionButton.extended(
heroTag: "direction",
backgroundColor: Colors.green,
onPressed: () => setState(() {
_controller1.forward();
_controller1.status == AnimationStatus.completed
? _controller1.reverse()
: _controller1.forward();
}),
icon: Icon(
Icons.movie_filter,
color: Colors.white,
),
label: Text(
"Animate",
style: TextStyle(color: Colors.white),
),
),
),
),
Align(
alignment: Alignment.bottomRight,
child: Padding(
padding: const EdgeInsets.only(right: 24.0),
/// Fab to control animation speed
child: FloatingActionButton.extended(
heroTag: "speed",
backgroundColor: Colors.white,
onPressed: () => setState(() {
_controller1.duration.inSeconds == 2
? _controller1.duration =
const Duration(seconds: 10)
: _controller1.duration =
const Duration(seconds: 2);
_controller1.duration.inSeconds == 2
? speedFabText = "Slowly"
: speedFabText = "Normal";
}),
icon: Icon(
Icons.slow_motion_video,
color: Colors.black,
),
label: Text(
speedFabText,
style: TextStyle(color: Colors.black),
),
),
),
),
],
),
],
),
),
);
}
@override
void dispose() {
_controller1.dispose();
super.dispose();
}
}
Widget animatedIconRow(AnimationController controller, AnimatedIconData icon1,
AnimatedIconData icon2, AnimatedIconData icon3) =>
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
AnimatedIcon(
size: 34.0,
icon: icon1,
progress: controller,
),
AnimatedIcon(
size: 34.0,
icon: icon2,
progress: controller,
),
AnimatedIcon(
size: 34.0,
icon: icon3,
progress: controller,
),
],
);