Skip to content

Commit

Permalink
Add day id to the gym state provider
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandgeider committed Jan 18, 2025
1 parent c397e10 commit 9bb3567
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/providers/gym_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,34 @@ 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,
);
}
}

class GymStateNotifier extends StateNotifier<GymState> {
final _prefs = SharedPreferences.getInstance();

GymStateNotifier() : super(GymState()) {
GymStateNotifier() : super(const GymState()) {
_loadSavedState();
}

Expand All @@ -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,
);
}
}
3 changes: 3 additions & 0 deletions lib/widgets/routines/gym_mode.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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!;
Expand Down Expand Up @@ -902,6 +904,7 @@ class _SessionPageState extends State<SessionPage> {
context,
listen: false,
).addSession(_session);

if (mounted) {
Navigator.of(context).pop();
}
Expand Down

0 comments on commit 9bb3567

Please sign in to comment.