Add day id to the gym state provider

This commit is contained in:
Roland Geider
2025-01-18 15:15:42 +01:00
parent c397e10e3f
commit 9bb3567835
2 changed files with 17 additions and 2 deletions

View File

@@ -13,22 +13,26 @@ class GymState {
final Map<Exercise, int> 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<Exercise, int>? 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<GymState> {
final _prefs = SharedPreferences.getInstance();
GymStateNotifier() : super(GymState()) {
GymStateNotifier() : super(const GymState()) {
_loadSavedState();
}
@@ -59,4 +63,12 @@ class GymStateNotifier extends StateNotifier<GymState> {
void setExercisePages(Map<Exercise, int> exercisePages) {
state = state.copyWith(exercisePages: exercisePages);
}
void clear() {
state = state.copyWith(
exercisePages: {},
currentPage: 0,
dayId: null,
);
}
}

View File

@@ -748,6 +748,8 @@ class _SessionPageState extends State<SessionPage> {
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<SessionPage> {
context,
listen: false,
).addSession(_session);
if (mounted) {
Navigator.of(context).pop();
}