Skip to content

Commit 09b56d3

Browse files
committed
i have no idea why this works!
reseting animation before starting the next set seem to have worked!
1 parent 0595bd6 commit 09b56d3

File tree

1 file changed

+96
-77
lines changed

1 file changed

+96
-77
lines changed

lib/vinyl/vinyl.dart

Lines changed: 96 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class TransformApp extends StatefulWidget {
3434
}
3535

3636
class _TransformAppState extends State<TransformApp>
37-
with SingleTickerProviderStateMixin {
37+
with TickerProviderStateMixin {
3838
late AnimationController animController;
3939
late Animation<double> _flipAnimation;
4040
late Animation<double> _pushBackAnimation;
@@ -50,76 +50,8 @@ class _TransformAppState extends State<TransformApp>
5050
@override
5151
void initState() {
5252
super.initState();
53-
animController = AnimationController(
54-
vsync: this, duration: const Duration(milliseconds: 1000))
55-
..addListener(_animationHooks);
5653

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();
12355
}
12456

12557
@override
@@ -209,17 +141,20 @@ class _TransformAppState extends State<TransformApp>
209141
return Stack(
210142
children: List.generate(_vinylItems.length, (index) {
211143
var vinylItem = _vinylItems[index];
212-
if (vinylItem.id == 'vinyl_3') {
144+
// if (vinylItem.id == 'vinyl_3') {
145+
if (vinylItem.id == vinylOrder[0]) {
213146
vinylItem.verticalAnimationValue =
214147
_combinedVerticalAnimation.value;
215148
vinylItem.zPositionValue =
216149
lerpDouble(-100.0, 0.0, _pushBackAnimation.value)!;
217150
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]) {
219153
vinylItem.verticalAnimationValue = _topJumpAnimation.value;
220154
vinylItem.zPositionValue = -50.0 + _topMoveForwardAnimation.value;
221155
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]) {
223158
vinylItem.verticalAnimationValue = _topJumpAnimation.value;
224159
vinylItem.zPositionValue =
225160
(-0 * 50.0) + _topMoveForwardAnimation.value;
@@ -250,6 +185,94 @@ class _TransformAppState extends State<TransformApp>
250185
);
251186
}
252187

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+
253276
Widget _buildSlider({
254277
required double value,
255278
required ValueChanged<double> onChanged,
@@ -278,10 +301,6 @@ class _TransformAppState extends State<TransformApp>
278301
} else if (animController.value < 0.5) {
279302
_isStackReordered = false;
280303
}
281-
282-
if (animController.isCompleted) {
283-
_changeAnimationListOrder();
284-
}
285304
}
286305

287306
// Update called in the middle of animation to make the card go behind another card!

0 commit comments

Comments
 (0)