From 9bb356783557f3d26cfd1611d70d0b5c1caec666 Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Sat, 18 Jan 2025 15:15:42 +0100 Subject: [PATCH] Add day id to the gym state provider --- lib/providers/gym_state.dart | 16 ++++++++++++++-- lib/widgets/routines/gym_mode.dart | 3 +++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/providers/gym_state.dart b/lib/providers/gym_state.dart index 4535148a..89afa0bb 100644 --- a/lib/providers/gym_state.dart +++ b/lib/providers/gym_state.dart @@ -13,22 +13,26 @@ class GymState { final Map exercisePages; final bool showExercisePages; final int currentPage; + final int? dayId; - GymState({ + const GymState({ this.exercisePages = const {}, this.showExercisePages = true, this.currentPage = 0, + this.dayId = null, }); GymState copyWith({ Map? exercisePages, bool? showExercisePages, int? currentPage, + int? dayId, }) { return GymState( exercisePages: exercisePages ?? this.exercisePages, showExercisePages: showExercisePages ?? this.showExercisePages, currentPage: currentPage ?? this.currentPage, + dayId: dayId ?? this.dayId, ); } } @@ -36,7 +40,7 @@ class GymState { class GymStateNotifier extends StateNotifier { final _prefs = SharedPreferences.getInstance(); - GymStateNotifier() : super(GymState()) { + GymStateNotifier() : super(const GymState()) { _loadSavedState(); } @@ -59,4 +63,12 @@ class GymStateNotifier extends StateNotifier { void setExercisePages(Map exercisePages) { state = state.copyWith(exercisePages: exercisePages); } + + void clear() { + state = state.copyWith( + exercisePages: {}, + currentPage: 0, + dayId: null, + ); + } } diff --git a/lib/widgets/routines/gym_mode.dart b/lib/widgets/routines/gym_mode.dart index 74f90fe1..b45729b6 100644 --- a/lib/widgets/routines/gym_mode.dart +++ b/lib/widgets/routines/gym_mode.dart @@ -748,6 +748,8 @@ class _SessionPageState extends State { void initState() { super.initState(); + // ref.read(gymStateProvider.notifier).clear(); + timeStartController.text = timeToString(widget._start)!; timeEndController.text = timeToString(TimeOfDay.now())!; _session.routineId = widget._workoutPlan.id!; @@ -902,6 +904,7 @@ class _SessionPageState extends State { context, listen: false, ).addSession(_session); + if (mounted) { Navigator.of(context).pop(); }