@@ -34,7 +34,7 @@ class TransformApp extends StatefulWidget {
34
34
}
35
35
36
36
class _TransformAppState extends State <TransformApp >
37
- with SingleTickerProviderStateMixin {
37
+ with TickerProviderStateMixin {
38
38
late AnimationController animController;
39
39
late Animation <double > _flipAnimation;
40
40
late Animation <double > _pushBackAnimation;
@@ -50,76 +50,8 @@ class _TransformAppState extends State<TransformApp>
50
50
@override
51
51
void initState () {
52
52
super .initState ();
53
- animController = AnimationController (
54
- vsync: this , duration: const Duration (milliseconds: 1000 ))
55
- ..addListener (_animationHooks);
56
53
57
- // Combine vertical animations on the first Vinyl!
58
- _combinedVerticalAnimation = TweenSequence <double >([
59
- TweenSequenceItem (
60
- tween: Tween <double >(begin: 0.0 , end: 120.0 ).chain (
61
- CurveTween (curve: Interval (0.0 , 0.33 , curve: Curves .linear))),
62
- weight: 33.0 ,
63
- ),
64
- TweenSequenceItem (
65
- tween: Tween <double >(begin: 120.0 , end: 120.0 ).chain (
66
- CurveTween (curve: Interval (0.33 , 0.5 , curve: Curves .linear))),
67
- weight: 17.0 ,
68
- ),
69
- TweenSequenceItem (
70
- tween: Tween <double >(begin: 120.0 , end: 0.0 )
71
- .chain (CurveTween (curve: Interval (0.5 , 1.0 , curve: Curves .linear))),
72
- weight: 50.0 ,
73
- ),
74
- ]).animate (animController);
75
-
76
- //1. Top to down from 0 to 90*
77
- //2. from 90* to 270*
78
- //3. from 270* to 0
79
- _flipAnimation = TweenSequence <double >([
80
- TweenSequenceItem (
81
- tween: Tween <double >(begin: 0.0 , end: pi / 2 )
82
- .chain (CurveTween (curve: Curves .linear)),
83
- weight: 25.0 ,
84
- ),
85
- TweenSequenceItem (
86
- tween: Tween <double >(begin: pi / 2 , end: 3 * pi / 2 )
87
- .chain (CurveTween (curve: Curves .linear)),
88
- weight: 50.0 ,
89
- ),
90
- TweenSequenceItem (
91
- tween: Tween <double >(begin: 3 * pi / 2 , end: 2 * pi)
92
- .chain (CurveTween (curve: Curves .linear)),
93
- weight: 25.0 ,
94
- ),
95
- ]).animate (animController);
96
-
97
- _pushBackAnimation = Tween <double >(begin: 0 , end: 1 ).animate (
98
- CurvedAnimation (
99
- parent: animController,
100
- curve: Interval (0.13 , 0.85 , curve: Curves .linear),
101
- ),
102
- );
103
-
104
- _topJumpAnimation = TweenSequence <double >([
105
- TweenSequenceItem (
106
- tween: Tween <double >(begin: 0.0 , end: - 120 )
107
- .chain (CurveTween (curve: Curves .linear)),
108
- weight: 50.0 ,
109
- ),
110
- TweenSequenceItem (
111
- tween: Tween <double >(begin: - 120 , end: 0.0 )
112
- .chain (CurveTween (curve: Curves .linear)),
113
- weight: 50.0 ,
114
- ),
115
- ]).animate (animController);
116
-
117
- _topMoveForwardAnimation = Tween <double >(begin: 0.0 , end: - 50 ).animate (
118
- CurvedAnimation (
119
- parent: animController,
120
- curve: Interval (0.0 , 1.0 , curve: Curves .linear),
121
- ),
122
- );
54
+ initAnimations ();
123
55
}
124
56
125
57
@override
@@ -209,17 +141,20 @@ class _TransformAppState extends State<TransformApp>
209
141
return Stack (
210
142
children: List .generate (_vinylItems.length, (index) {
211
143
var vinylItem = _vinylItems[index];
212
- if (vinylItem.id == 'vinyl_3' ) {
144
+ // if (vinylItem.id == 'vinyl_3') {
145
+ if (vinylItem.id == vinylOrder[0 ]) {
213
146
vinylItem.verticalAnimationValue =
214
147
_combinedVerticalAnimation.value;
215
148
vinylItem.zPositionValue =
216
149
lerpDouble (- 100.0 , 0.0 , _pushBackAnimation.value)! ;
217
150
vinylItem.rotateX = _flipAnimation.value;
218
- } else if (_vinylItems[index].id == 'vinyl_2' ) {
151
+ // } else if (_vinylItems[index].id == 'vinyl_2') {
152
+ } else if (_vinylItems[index].id == vinylOrder[1 ]) {
219
153
vinylItem.verticalAnimationValue = _topJumpAnimation.value;
220
154
vinylItem.zPositionValue = - 50.0 + _topMoveForwardAnimation.value;
221
155
vinylItem.rotateX = 0.0 ;
222
- } else if (_vinylItems[index].id == 'vinyl_1' ) {
156
+ // } else if (_vinylItems[index].id == 'vinyl_1') {
157
+ } else if (_vinylItems[index].id == vinylOrder[2 ]) {
223
158
vinylItem.verticalAnimationValue = _topJumpAnimation.value;
224
159
vinylItem.zPositionValue =
225
160
(- 0 * 50.0 ) + _topMoveForwardAnimation.value;
@@ -250,6 +185,94 @@ class _TransformAppState extends State<TransformApp>
250
185
);
251
186
}
252
187
188
+ void resetAnimation () {
189
+ animController.dispose ();
190
+ // animController.reset();
191
+ initAnimations ();
192
+ // animController.forward();
193
+ }
194
+
195
+ initAnimations () {
196
+ animController = AnimationController (
197
+ vsync: this , duration: const Duration (milliseconds: 1000 ))
198
+ ..addListener (_animationHooks);
199
+ // Add a status listener
200
+ animController.addStatusListener ((status) {
201
+ if (status == AnimationStatus .completed) {
202
+ // Trigger your function here
203
+ print ("animation completed | resetting now" );
204
+ resetAnimation ();
205
+ _changeAnimationListOrder ();
206
+ }
207
+ });
208
+ // Combine vertical animations on the first Vinyl!
209
+ _combinedVerticalAnimation = TweenSequence <double >([
210
+ TweenSequenceItem (
211
+ tween: Tween <double >(begin: 0.0 , end: 120.0 ).chain (
212
+ CurveTween (curve: Interval (0.0 , 0.33 , curve: Curves .linear))),
213
+ weight: 33.0 ,
214
+ ),
215
+ TweenSequenceItem (
216
+ tween: Tween <double >(begin: 120.0 , end: 120.0 ).chain (
217
+ CurveTween (curve: Interval (0.33 , 0.5 , curve: Curves .linear))),
218
+ weight: 17.0 ,
219
+ ),
220
+ TweenSequenceItem (
221
+ tween: Tween <double >(begin: 120.0 , end: 0.0 )
222
+ .chain (CurveTween (curve: Interval (0.5 , 1.0 , curve: Curves .linear))),
223
+ weight: 50.0 ,
224
+ ),
225
+ ]).animate (animController);
226
+
227
+ //1. Top to down from 0 to 90*
228
+ //2. from 90* to 270*
229
+ //3. from 270* to 0
230
+ _flipAnimation = TweenSequence <double >([
231
+ TweenSequenceItem (
232
+ tween: Tween <double >(begin: 0.0 , end: pi / 2 )
233
+ .chain (CurveTween (curve: Curves .linear)),
234
+ weight: 25.0 ,
235
+ ),
236
+ TweenSequenceItem (
237
+ tween: Tween <double >(begin: pi / 2 , end: 3 * pi / 2 )
238
+ .chain (CurveTween (curve: Curves .linear)),
239
+ weight: 50.0 ,
240
+ ),
241
+ TweenSequenceItem (
242
+ tween: Tween <double >(begin: 3 * pi / 2 , end: 2 * pi)
243
+ .chain (CurveTween (curve: Curves .linear)),
244
+ weight: 25.0 ,
245
+ ),
246
+ ]).animate (animController);
247
+
248
+ _pushBackAnimation = Tween <double >(begin: 0 , end: 1 ).animate (
249
+ CurvedAnimation (
250
+ parent: animController,
251
+ curve: Interval (0.13 , 0.85 , curve: Curves .linear),
252
+ ),
253
+ );
254
+
255
+ _topJumpAnimation = TweenSequence <double >([
256
+ TweenSequenceItem (
257
+ tween: Tween <double >(begin: 0.0 , end: - 120 )
258
+ .chain (CurveTween (curve: Curves .linear)),
259
+ weight: 50.0 ,
260
+ ),
261
+ TweenSequenceItem (
262
+ tween: Tween <double >(begin: - 120 , end: 0.0 )
263
+ .chain (CurveTween (curve: Curves .linear)),
264
+ weight: 50.0 ,
265
+ ),
266
+ ]).animate (animController);
267
+
268
+ _topMoveForwardAnimation = Tween <double >(begin: 0.0 , end: - 50 ).animate (
269
+ CurvedAnimation (
270
+ parent: animController,
271
+ curve: Interval (0.0 , 1.0 , curve: Curves .linear),
272
+ ),
273
+ );
274
+ }
275
+
253
276
Widget _buildSlider ({
254
277
required double value,
255
278
required ValueChanged <double > onChanged,
@@ -278,10 +301,6 @@ class _TransformAppState extends State<TransformApp>
278
301
} else if (animController.value < 0.5 ) {
279
302
_isStackReordered = false ;
280
303
}
281
-
282
- if (animController.isCompleted) {
283
- _changeAnimationListOrder ();
284
- }
285
304
}
286
305
287
306
// Update called in the middle of animation to make the card go behind another card!
0 commit comments