mirror of
https://github.com/wger-project/flutter.git
synced 2026-02-18 00:17:48 +01:00
Add day id to the gym state provider
This commit is contained in:
@@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user