1+ /*
2+ * This file is part of wger Workout Manager <https://github.com/wger-project>.
3+ * Copyright (C) 2020, 2025 wger Team
4+ *
5+ * wger Workout Manager is free software: you can redistribute it and/or modify
6+ * it under the terms of the GNU Affero General Public License as published by
7+ * the Free Software Foundation, either version 3 of the License, or
8+ * (at your option) any later version.
9+ *
10+ * This program is distributed in the hope that it will be useful,
11+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+ * GNU Affero General Public License for more details.
14+ *
15+ * You should have received a copy of the GNU Affero General Public License
16+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
17+ */
18+
119import 'package:flutter/material.dart' ;
20+ import 'package:flutter_riverpod/flutter_riverpod.dart' ;
221import 'package:provider/provider.dart' ;
322import 'package:wger/exceptions/http_exception.dart' ;
423import 'package:wger/helpers/consts.dart' ;
524import 'package:wger/helpers/errors.dart' ;
625import 'package:wger/l10n/generated/app_localizations.dart' ;
726import 'package:wger/models/exercises/exercise.dart' ;
827import 'package:wger/providers/add_exercise.dart' ;
9- import 'package:wger/providers/exercises .dart' ;
28+ import 'package:wger/providers/exercise_state_notifier .dart' ;
1029import 'package:wger/providers/user.dart' ;
1130import 'package:wger/screens/exercise_screen.dart' ;
1231import 'package:wger/widgets/add_exercise/steps/step_1_basics.dart' ;
@@ -33,7 +52,7 @@ class AddExerciseScreen extends StatelessWidget {
3352 }
3453}
3554
36- class AddExerciseStepper extends StatefulWidget {
55+ class AddExerciseStepper extends ConsumerStatefulWidget {
3756 const AddExerciseStepper ({super .key});
3857
3958 static const STEPS_IN_FORM = 6 ;
@@ -42,7 +61,7 @@ class AddExerciseStepper extends StatefulWidget {
4261 _AddExerciseStepperState createState () => _AddExerciseStepperState ();
4362}
4463
45- class _AddExerciseStepperState extends State <AddExerciseStepper > {
64+ class _AddExerciseStepperState extends ConsumerState <AddExerciseStepper > {
4665 int _currentStep = 0 ;
4766 int lastStepIndex = AddExerciseStepper .STEPS_IN_FORM - 1 ;
4867 bool _isLoading = false ;
@@ -81,12 +100,11 @@ class _AddExerciseStepperState extends State<AddExerciseStepper> {
81100 errorWidget = const SizedBox .shrink ();
82101 });
83102 final addExerciseProvider = context.read <AddExerciseProvider >();
84- final exerciseProvider = context.read <ExercisesProvider >();
85103
86104 Exercise ? exercise;
87105 try {
88106 final exerciseId = await addExerciseProvider.postExerciseToServer ();
89- exercise = await exerciseProvider. fetchAndSetExercise (exerciseId);
107+ exercise = ref. read (exerciseStateProvider.notifier). getById (exerciseId);
90108 } on WgerHttpException catch (error) {
91109 if (context.mounted) {
92110 setState (() {
0 commit comments