@@ -2,16 +2,18 @@ import 'package:flutter/material.dart';
2
2
import 'dart:math' ;
3
3
4
4
class FlipLoader extends StatefulWidget {
5
- Color loaderBackground;
6
- Color iconColor;
7
- IconData icon;
8
- String animationType;
5
+ final Color loaderBackground;
6
+ final Color iconColor;
7
+ final IconData icon;
8
+ final String animationType;
9
+ final String shape;
10
+ final bool rotateIcon;
9
11
10
- FlipLoader ({this .loaderBackground = Colors .redAccent, this .iconColor = Colors .white, this .icon = Icons .sync , this .animationType = "full_flip" });
12
+ FlipLoader ({this .loaderBackground = Colors .redAccent, this .iconColor = Colors .white, this .icon = Icons .sync , this .animationType = "full_flip" , this .shape = "square" , this .rotateIcon = true });
11
13
12
14
13
15
@override
14
- _FlipLoaderState createState () => _FlipLoaderState (this .loaderBackground, this .iconColor, this .icon, this .animationType);
16
+ _FlipLoaderState createState () => _FlipLoaderState (this .loaderBackground, this .iconColor, this .icon, this .animationType, this .shape, this .rotateIcon );
15
17
}
16
18
17
19
class _FlipLoaderState extends State <FlipLoader >
@@ -25,8 +27,10 @@ class _FlipLoaderState extends State<FlipLoader>
25
27
IconData icon;
26
28
Widget loaderIconChild;
27
29
String animationType;
30
+ String shape;
31
+ bool rotateIcon;
28
32
29
- _FlipLoaderState (this .loaderColor, this .iconColor, this .icon, this .animationType);
33
+ _FlipLoaderState (this .loaderColor, this .iconColor, this .icon, this .animationType, this .shape, this .rotateIcon );
30
34
31
35
@override
32
36
void initState () {
@@ -37,7 +41,6 @@ class _FlipLoaderState extends State<FlipLoader>
37
41
controller.addStatusListener ((status){
38
42
// Play animation backwards and forwards for full flip
39
43
if (animationType == "half_flip" ) {
40
- print ('half line 40' );
41
44
if (status == AnimationStatus .completed) {
42
45
setState (() {
43
46
controller.repeat ();
@@ -46,15 +49,14 @@ class _FlipLoaderState extends State<FlipLoader>
46
49
}
47
50
// play animation on repeat for half flip
48
51
else if (animationType == "full_flip" ) {
49
- print ('full line 57' );
50
- if (status == AnimationStatus .completed) {
52
+ if (status == AnimationStatus .dismissed) {
51
53
setState (() {
52
- controller.reverse ();
54
+ controller.forward ();
53
55
});
54
56
}
55
- if (status == AnimationStatus .dismissed ) {
57
+ if (status == AnimationStatus .completed ) {
56
58
setState (() {
57
- controller.forward ();
59
+ controller.repeat ();
58
60
});
59
61
}
60
62
}
@@ -72,29 +74,29 @@ class _FlipLoaderState extends State<FlipLoader>
72
74
73
75
switch (type) {
74
76
case "half_flip" :
75
- animCtrl = AnimationController (duration: const Duration (milliseconds: 2000 ), vsync: this );
77
+ animCtrl = AnimationController (duration: const Duration (milliseconds: 4000 ), vsync: this );
76
78
77
79
// Horizontal animation
78
80
this .rotationHorizontal = Tween <double >(begin: 0.0 , end: 1.0 ).animate (
79
81
CurvedAnimation (
80
82
parent: animCtrl,
81
- curve: Interval (0.0 , 0.50 , curve: Curves .fastOutSlowIn )));
83
+ curve: Interval (0.0 , 0.50 , curve: Curves .linear )));
82
84
83
85
// Vertical animation
84
86
this .rotationVertical = Tween <double >(begin: 0.0 , end: 1.0 ).animate (
85
87
CurvedAnimation (
86
88
parent: animCtrl,
87
- curve: Interval (0.50 , 1.0 , curve: Curves .fastOutSlowIn )));
89
+ curve: Interval (0.50 , 1.0 , curve: Curves .linear )));
88
90
break ;
89
91
case "full_flip" :
90
92
default :
91
- animCtrl = AnimationController (duration: const Duration (milliseconds: 4000 ), vsync: this );
93
+ animCtrl = AnimationController (duration: const Duration (milliseconds: 2000 ), vsync: this );
92
94
93
- this .rotationHorizontal = Tween <double >(begin: - 1 .0 , end: 1.0 ).animate (
95
+ this .rotationHorizontal = Tween <double >(begin: 0 .0 , end: 1.0 ).animate (
94
96
CurvedAnimation (
95
97
parent: animCtrl,
96
98
curve: Interval (0.0 , 0.50 , curve: Curves .linear)));
97
- this .rotationVertical = Tween <double >(begin: - 1 .0 , end: 1.0 ).animate (
99
+ this .rotationVertical = Tween <double >(begin: 0 .0 , end: 1.0 ).animate (
98
100
CurvedAnimation (
99
101
parent: animCtrl,
100
102
curve: Interval (0.50 , 1.0 , curve: Curves .linear)));
@@ -107,9 +109,9 @@ class _FlipLoaderState extends State<FlipLoader>
107
109
@override
108
110
Widget build (BuildContext context) {
109
111
if (animationType == "half_flip" ) {
110
- return buildFullFlipper (context);
111
- } else {
112
112
return buildHalfFlipper (context);
113
+ } else {
114
+ return buildFullFlipper (context);
113
115
}
114
116
}
115
117
@@ -121,18 +123,27 @@ class _FlipLoaderState extends State<FlipLoader>
121
123
child: new Transform (
122
124
transform: Matrix4 .identity ()
123
125
..setEntry (3 , 2 , 0.006 )
124
- ..rotateX (sin (pi * rotationVertical.value))
125
- ..rotateY (sin (pi * rotationHorizontal.value)),
126
+ ..rotateX (sin (2 * pi * rotationVertical.value))
127
+ ..rotateY (sin (2 * pi * rotationHorizontal.value)),
126
128
alignment: Alignment .center,
127
129
child: Container (
128
130
decoration: BoxDecoration (
129
- borderRadius: new BorderRadius .all (const Radius .circular (8.0 )),
131
+ shape: shape == "circle" ? BoxShape .circle : BoxShape .rectangle,
132
+ borderRadius: shape == "circle" ? null : new BorderRadius .all (const Radius .circular (8.0 )),
130
133
color: loaderColor,
131
134
),
132
135
width: 40.0 ,
133
136
height: 40.0 ,
134
- child: new RotationTransition (
137
+ child: rotateIcon == true ? new RotationTransition (
135
138
turns: rotationHorizontal.value == 1.0 ? rotationVertical : rotationHorizontal,
139
+ child: new Center (
140
+ child: Icon (
141
+ icon,
142
+ color: iconColor,
143
+ size: 20.0 ,
144
+ ),
145
+ ),
146
+ ) : Center (
136
147
child: Icon (
137
148
icon,
138
149
color: iconColor,
@@ -154,19 +165,20 @@ class _FlipLoaderState extends State<FlipLoader>
154
165
child: new Transform (
155
166
transform: Matrix4 .identity ()
156
167
..setEntry (3 , 2 , 0.006 )
157
- ..rotateX ((pi * rotationVertical.value))
158
- ..rotateY ((pi * rotationHorizontal.value)),
168
+ ..rotateX ((2 * pi * rotationVertical.value))
169
+ ..rotateY ((2 * pi * rotationHorizontal.value)),
159
170
alignment: Alignment .center,
160
171
child: Container (
161
172
decoration: BoxDecoration (
162
- borderRadius: new BorderRadius .all (const Radius .circular (8.0 )),
173
+ shape: shape == "circle" ? BoxShape .circle : BoxShape .rectangle,
174
+ borderRadius: shape == "circle" ? null : new BorderRadius .all (const Radius .circular (8.0 )),
163
175
color: loaderColor,
164
176
),
165
177
width: 40.0 ,
166
178
height: 40.0 ,
167
179
child: new Center (
168
180
child: Icon (
169
- icon, color: iconColor
181
+ icon, color: iconColor, size : 20.0 ,
170
182
),
171
183
),
172
184
),
0 commit comments