@@ -43,9 +43,10 @@ class _TransformAppState extends State<TransformApp>
43
43
late Animation <double > _topJumpAnimation;
44
44
late Animation <double > _topMoveForwardAnimation;
45
45
46
- final List <VinylItem > _vinylItems = vinylItems;
46
+ final List <VinylItem > _vinylItems = List .from (vinylItems);
47
+
48
+ String firstVinylId = vinylItems[0 ].id;
47
49
48
- // double _manualValue = 0;
49
50
@override
50
51
void initState () {
51
52
super .initState ();
@@ -106,11 +107,6 @@ class _TransformAppState extends State<TransformApp>
106
107
.chain (CurveTween (curve: Curves .linear)),
107
108
weight: 50.0 ,
108
109
),
109
- // TweenSequenceItem(
110
- // tween: Tween<double>(begin: -120, end: -120)
111
- // .chain(CurveTween(curve: Curves.linear)),
112
- // weight: 20.0,
113
- // ),
114
110
TweenSequenceItem (
115
111
tween: Tween <double >(begin: - 120 , end: 0.0 )
116
112
.chain (CurveTween (curve: Curves .linear)),
@@ -136,7 +132,7 @@ class _TransformAppState extends State<TransformApp>
136
132
Widget build (BuildContext context) {
137
133
return Scaffold (
138
134
body: GestureDetector (
139
- onTap: () => _changeOrder (),
135
+ onTap: () => _changeStackOrder (),
140
136
child: Expanded (
141
137
child: Stack (
142
138
fit: StackFit .expand,
@@ -182,11 +178,10 @@ class _TransformAppState extends State<TransformApp>
182
178
padding:
183
179
EdgeInsets .symmetric (horizontal: 40.0 , vertical: 20.0 ),
184
180
shape: RoundedRectangleBorder (
185
- borderRadius: BorderRadius .circular (
186
- 4.0 ), // Change this value for different radii
181
+ borderRadius: BorderRadius .circular (4.0 ),
187
182
),
188
- foregroundColor: Colors .black, // Text color
189
- backgroundColor: Colors .white, // Background color
183
+ foregroundColor: Colors .black,
184
+ backgroundColor: Colors .white,
190
185
),
191
186
onPressed: () {
192
187
animController.forward ();
@@ -213,29 +208,29 @@ class _TransformAppState extends State<TransformApp>
213
208
builder: (context, child) {
214
209
return Stack (
215
210
children: List .generate (_vinylItems.length, (index) {
216
- var verticalAnimationValue = 0.0 ;
217
- var zPositionValue = 0.0 ;
218
- var rotateX = 0.0 ;
219
- if (_vinylItems[index].id == 'vinyl_3' ) {
220
- verticalAnimationValue = _combinedVerticalAnimation.value;
221
- zPositionValue =
211
+ var vinylItem = _vinylItems[index];
212
+ if (vinylItem.id == 'vinyl_3' ) {
213
+ vinylItem.verticalAnimationValue =
214
+ _combinedVerticalAnimation.value;
215
+ vinylItem.zPositionValue =
222
216
lerpDouble (- 100.0 , 0.0 , _pushBackAnimation.value)! ;
223
- rotateX = _flipAnimation.value;
224
- // lerpDouble(0.0, 2 * pi, _flipAnimation.value)!;
217
+ vinylItem.rotateX = _flipAnimation.value;
225
218
} else if (_vinylItems[index].id == 'vinyl_2' ) {
226
- verticalAnimationValue = _topJumpAnimation.value;
227
- zPositionValue = - 50.0 + _topMoveForwardAnimation.value;
228
- rotateX = 0.0 ;
219
+ vinylItem. verticalAnimationValue = _topJumpAnimation.value;
220
+ vinylItem. zPositionValue = - 50.0 + _topMoveForwardAnimation.value;
221
+ vinylItem. rotateX = 0.0 ;
229
222
} else if (_vinylItems[index].id == 'vinyl_1' ) {
230
- verticalAnimationValue = _topJumpAnimation.value;
231
- zPositionValue = (- 0 * 50.0 ) + _topMoveForwardAnimation.value;
232
- rotateX = 0.0 ;
223
+ vinylItem.verticalAnimationValue = _topJumpAnimation.value;
224
+ vinylItem.zPositionValue =
225
+ (- 0 * 50.0 ) + _topMoveForwardAnimation.value;
226
+ vinylItem.rotateX = 0.0 ;
233
227
}
234
228
235
229
return Transform (
236
230
transform: Matrix4 .identity ()
237
- ..translate (0.0 , verticalAnimationValue, zPositionValue)
238
- ..rotateX (rotateX),
231
+ ..translate (0.0 , vinylItem.verticalAnimationValue,
232
+ vinylItem.zPositionValue)
233
+ ..rotateX (vinylItem.rotateX),
239
234
alignment: Alignment .center, // -index * 50.0
240
235
child: Container (
241
236
width: 200 ,
@@ -251,76 +246,10 @@ class _TransformAppState extends State<TransformApp>
251
246
);
252
247
}),
253
248
);
254
-
255
- // Stack(
256
- // children: [
257
- // Transform(
258
- // transform: Matrix4.identity()
259
- // ..translate(0.0, 0.0, 0.0), // -index * 50.0
260
- // child: Container(
261
- // width: 200,
262
- // height: 200,
263
- // color: Colors.green,
264
- // child: Center(
265
- // child: Text(
266
- // 'Layer 1',
267
- // style: TextStyle(color: Colors.white),
268
- // ),
269
- // ),
270
- // ),
271
- // ),
272
- // Transform(
273
- // transform: Matrix4.identity()
274
- // ..translate(0.0, 0.0, -50.0), // -index * 50.0
275
- // child: Container(
276
- // width: 200,
277
- // height: 200,
278
- // color: Colors.yellow,
279
- // child: Center(
280
- // child: Text(
281
- // 'Layer 2',
282
- // style: TextStyle(color: Colors.white),
283
- // ),
284
- // ),
285
- // ),
286
- // ),
287
- // Transform(
288
- // transform: Matrix4.identity()
289
- // ..translate(
290
- // 0.0,
291
- // _combinedVerticalAnimation.value,
292
- // // combinedLerp(
293
- // // 0.0, 200.0, _freeFallAnimation, _goBackUPAnimation),
294
- // // lerpDouble(0.0, 200.0, _freeFallAnimation.value)!,
295
- // lerpDouble(-100.0, 0.0, _pushBackAnimation.value)!)
296
- // ..rotateX(lerpDouble(
297
- // 0.0, 2 * pi, _flipAnimation.value)!), // -index * 50.0
298
- // alignment: Alignment.center,
299
- // child: Container(
300
- // width: 200,
301
- // height: 200,
302
- // color: Colors.purple,
303
- // child: Center(
304
- // child: Text(
305
- // 'Layer 3',
306
- // style: TextStyle(color: Colors.white),
307
- // ),
308
- // ),
309
- // ),
310
- // ),
311
- // ],
312
- // );
313
249
},
314
250
);
315
251
}
316
252
317
- _choreo () {
318
- //------------------
319
- //First vinyl translates down by Y + 200
320
- //First vinyl rotates
321
- //------------------
322
- }
323
-
324
253
Widget _buildSlider ({
325
254
required double value,
326
255
required ValueChanged <double > onChanged,
@@ -344,31 +273,75 @@ class _TransformAppState extends State<TransformApp>
344
273
bool _isStackReordered = false ;
345
274
_animationHooks () {
346
275
if (animController.value >= 0.5 && ! _isStackReordered) {
347
- _changeOrder ();
276
+ _changeStackOrder ();
348
277
_isStackReordered = true ;
349
278
} else if (animController.value < 0.5 ) {
350
279
_isStackReordered = false ;
351
280
}
281
+
282
+ if (animController.isCompleted) {
283
+ _changeAnimationListOrder ();
284
+ }
352
285
}
353
286
354
- void _changeOrder () {
355
- print ("_changeOrder" );
287
+ // Update called in the middle of animation to make the card go behind another card!
288
+ void _changeStackOrder () {
289
+ print ("_changeStackOrder" );
356
290
setState (() {
357
- VinylItem item = vinylItems.removeAt (2 );
358
- vinylItems.insert (0 , item);
291
+ VinylItem item = _vinylItems.removeAt (_vinylItems.length - 1 );
292
+ _vinylItems.insert (0 , item);
293
+ });
294
+ }
295
+
296
+ // Update called after the animation has finished
297
+ void _changeAnimationListOrder () {
298
+ print ("_changeAnimationListOrder" );
299
+ setState (() {
300
+ String firstElement = vinylOrder.removeAt (0 );
301
+ vinylOrder.add (firstElement);
359
302
});
360
303
}
361
304
}
362
305
363
306
class VinylItem {
364
307
final String id;
365
308
final Color color;
309
+ double verticalAnimationValue = 0.0 ;
310
+ double zPositionValue = 0.0 ;
311
+ double rotateX = 0.0 ;
366
312
367
- VinylItem ({required this .id, required this .color});
313
+ VinylItem (
314
+ {required this .id,
315
+ required this .color,
316
+ this .verticalAnimationValue = 0.0 ,
317
+ this .zPositionValue = 0.0 ,
318
+ this .rotateX = 0.0 });
368
319
}
369
320
321
+ // verticalAnimationValue = _combinedVerticalAnimation.value;
322
+ // zPositionValue =
323
+ // lerpDouble(-100.0, 0.0, _pushBackAnimation.value)!;
324
+ // rotateX = _flipAnimation.value;
325
+
370
326
final List <VinylItem > vinylItems = [
371
- VinylItem (id: 'vinyl_1' , color: Colors .green),
372
- VinylItem (id: 'vinyl_2' , color: Colors .yellow),
373
- VinylItem (id: 'vinyl_3' , color: Colors .purple),
327
+ VinylItem (
328
+ id: 'vinyl_1' ,
329
+ color: Colors .green,
330
+ verticalAnimationValue: 0.0 ,
331
+ zPositionValue: 0.0 ,
332
+ rotateX: 0.0 ),
333
+ VinylItem (
334
+ id: 'vinyl_2' ,
335
+ color: Colors .yellow,
336
+ verticalAnimationValue: 0.0 ,
337
+ zPositionValue: 0.0 ,
338
+ rotateX: 0.0 ),
339
+ VinylItem (
340
+ id: 'vinyl_3' ,
341
+ color: Colors .purple,
342
+ verticalAnimationValue: 0.0 ,
343
+ zPositionValue: 0.0 ,
344
+ rotateX: 0.0 ),
374
345
];
346
+
347
+ final vinylOrder = ['vinyl_3' , 'vinyl_2' , 'vinyl_1' ];
0 commit comments