Skip to content

Commit 54aeb8e

Browse files
committed
fixing incosistency in animation preview initstate func and prep animation logic
1 parent 1223984 commit 54aeb8e

4 files changed

Lines changed: 38 additions & 6 deletions

File tree

assets/animations/Ex15.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

assets/exercises/exercises.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,10 @@
310310
"benefits": "Strengthens and tones abdominal muscles; improves core stability and posture; trims waistline; enhances balance and stability",
311311
"contraindications": "lower_back_injury;neck_injury;osteoporosis;post_abdominal_surgery",
312312
"instructions": "Lie on your back, knees bent, feet flat on the floor, hands on chest or behind head.\nContract your abs and lift your shoulders off the floor, curling toward your knees.\nHold briefly at the top, then slowly lower back down and repeat.",
313-
"is_lottie": true,
313+
"is_lottie": false,
314314
"third_party": false,
315315
"equipments": "",
316-
"animation_link": "https://lottiefiles.com/free-animation/abs-crunches-kqvZGz4NGQ"
316+
"animation_link": "https://res.cloudinary.com/dyvolu8tc/video/upload/v1784020936/Abdominal_crunches_najeqv.mp4"
317317
},
318318
{
319319
"exercise_id": "Ex16",

lib/features/home/screens/session_execution_screen.dart

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import 'package:flutter/material.dart';
22
import 'package:flutter_riverpod/flutter_riverpod.dart';
3+
import 'package:go_router/go_router.dart';
4+
import 'package:move_your_body/core/routing/app_routes.dart';
5+
import 'package:move_your_body/core/model/exercise_data.dart';
36
import 'package:move_your_body/core/theme/app_colors.dart';
47
import 'package:move_your_body/core/widgets/app_scaffold.dart';
58
import 'package:move_your_body/features/home/models/session_execution_state.dart';
@@ -18,6 +21,12 @@ class SessionExecutionScreen extends ConsumerWidget {
1821

1922
@override
2023
Widget build(BuildContext context, WidgetRef ref) {
24+
ref.listen(sessionExecutionViewModelProvider(sessionId), (previous, next) {
25+
if (next.currentPhase == ExecutionPhase.finished) {
26+
context.go(AppRoutes.home);
27+
}
28+
});
29+
2130
final state = ref.watch(sessionExecutionViewModelProvider(sessionId));
2231
final bottomInset = MediaQuery.of(context).padding.bottom;
2332

@@ -84,6 +93,15 @@ class SessionExecutionScreen extends ConsumerWidget {
8493
nextExerciseName = state.exercises[state.currentExerciseIndex + 1].name;
8594
}
8695

96+
Exercise? nextAnimExercise;
97+
if (state.currentPhase == ExecutionPhase.preparation) {
98+
nextAnimExercise = currentExercise;
99+
} else if (state.currentPhase == ExecutionPhase.rest) {
100+
if (state.currentExerciseIndex + 1 < state.exercises.length) {
101+
nextAnimExercise = state.exercises[state.currentExerciseIndex + 1];
102+
}
103+
}
104+
87105
return AppScaffold(
88106
child: SafeArea(
89107
child: Padding(
@@ -109,9 +127,7 @@ class SessionExecutionScreen extends ConsumerWidget {
109127
child: ExecutionAnimationBox(
110128
exercise: currentExercise,
111129
isResting: isResting || state.currentPhase == ExecutionPhase.preparation,
112-
nextExercise: state.currentExerciseIndex + 1 < state.exercises.length
113-
? state.exercises[state.currentExerciseIndex + 1]
114-
: null,
130+
nextExercise: nextAnimExercise,
115131
),
116132
),
117133

lib/features/home/widgets/exercise_info/animation_preview.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,23 @@ class _AnimationPreviewState extends ConsumerState<AnimationPreview> {
3030
}
3131
}
3232

33+
@override
34+
void didUpdateWidget(AnimationPreview oldWidget) {
35+
super.didUpdateWidget(oldWidget);
36+
if (oldWidget.exercise.exerciseId != widget.exercise.exerciseId) {
37+
final oldController = _videoController;
38+
_videoController = null;
39+
_animationFile = null;
40+
_hasError = false;
41+
42+
oldController?.dispose();
43+
44+
if (!widget.exercise.isLottie && widget.exercise.animationLink.isNotEmpty) {
45+
_loadAnimation();
46+
}
47+
}
48+
}
49+
3350
Future<void> _loadAnimation() async {
3451
try {
3552
final file = await ref.read(

0 commit comments

Comments
 (0)