@@ -63,7 +63,7 @@ class RoutinesProvider with ChangeNotifier {
63
63
static const _routineConfigRestTime = 'rest-config' ;
64
64
static const _routineConfigMaxRestTime = 'max-rest-config' ;
65
65
66
- Routine ? _currentRoutine ;
66
+ Routine ? activeRoutine ;
67
67
late ExercisesProvider _exerciseProvider;
68
68
final WgerBaseProvider baseProvider;
69
69
List <Routine > _routines = [];
@@ -97,7 +97,7 @@ class RoutinesProvider with ChangeNotifier {
97
97
98
98
/// Clears all lists
99
99
void clear () {
100
- _currentRoutine = null ;
100
+ activeRoutine = null ;
101
101
_routines = [];
102
102
_weightUnits = [];
103
103
_repetitionUnits = [];
@@ -138,28 +138,14 @@ class RoutinesProvider with ChangeNotifier {
138
138
return _routines.indexWhere ((routine) => routine.id == id);
139
139
}
140
140
141
- /// Set the currently "active" workout plan
142
- void setCurrentPlan (int id) {
143
- _currentRoutine = findById (id);
144
- }
145
-
146
- /// Returns the currently "active" workout plan
147
- Routine ? get currentRoutine {
148
- return _currentRoutine;
149
- }
150
-
151
- /// Reset the currently "active" workout plan to null
152
- void resetCurrentRoutine () {
153
- _currentRoutine = null ;
154
- }
155
-
156
- /// Returns the current active workout plan. At the moment this is just
157
- /// the latest, but this might change in the future.
158
- Routine ? get activeRoutine {
141
+ /// Sets the current active routine. At the moment this is just the latest,
142
+ /// but this might change in the future.
143
+ void setActiveRoutine () {
159
144
if (_routines.isNotEmpty) {
160
- return _routines.first;
145
+ activeRoutine = _routines.first;
146
+ } else {
147
+ activeRoutine = null ;
161
148
}
162
- return null ;
163
149
}
164
150
165
151
/*
@@ -179,12 +165,13 @@ class RoutinesProvider with ChangeNotifier {
179
165
await fetchAndSetRoutineFull (entry['id' ]);
180
166
}
181
167
168
+ setActiveRoutine ();
182
169
notifyListeners ();
183
170
}
184
171
185
- /// Fetches all workout plan sparsely, i.e. only with the data on the plan
186
- /// object itself and no child attributes
187
- Future <void > fetchAndSetAllPlansSparse () async {
172
+ /// Fetches all routines sparsely, i.e. only with the data on the object itself
173
+ /// and no child attributes
174
+ Future <void > fetchAndSetAllRoutinesSparse () async {
188
175
final data = await baseProvider.fetch (
189
176
baseProvider.makeUrl (_routinesUrlPath, query: {'limit' : '1000' , 'is_template' : 'false' }),
190
177
);
@@ -194,7 +181,7 @@ class RoutinesProvider with ChangeNotifier {
194
181
_routines.add (plan);
195
182
}
196
183
197
- // _workoutPlans.sort((a, b) => b.created.compareTo(a.created) );
184
+ setActiveRoutine ( );
198
185
notifyListeners ();
199
186
}
200
187
@@ -216,18 +203,19 @@ class RoutinesProvider with ChangeNotifier {
216
203
}
217
204
}
218
205
219
- /// Fetches a workout plan sparsely, i.e. only with the data on the plan
220
- /// object itself and no child attributes
206
+ /// Fetches a routine sparsely, i.e. only with the data on the object itself
207
+ /// and no child attributes
221
208
Future <Routine > fetchAndSetRoutineSparse (int planId) async {
222
209
final fullPlanData = await baseProvider.fetch (
223
210
baseProvider.makeUrl (_routinesUrlPath, id: planId),
224
211
);
225
- final plan = Routine .fromJson (fullPlanData);
226
- _routines.add (plan );
212
+ final routine = Routine .fromJson (fullPlanData);
213
+ _routines.add (routine );
227
214
_routines.sort ((a, b) => b.created.compareTo (a.created));
228
215
216
+ setActiveRoutine ();
229
217
notifyListeners ();
230
- return plan ;
218
+ return routine ;
231
219
}
232
220
233
221
/// Fetches a workout plan fully, i.e. with all corresponding child attributes
@@ -306,7 +294,7 @@ class RoutinesProvider with ChangeNotifier {
306
294
routine.dayDataGym = dayDataEntriesGym;
307
295
308
296
// Logs
309
- routine.sessions = List <WorkoutSessionApi >.from (sessionDataEntries);
297
+ routine.sessions = List <WorkoutSessionApi >.of (sessionDataEntries);
310
298
for (final session in routine.sessions) {
311
299
for (final log in session.logs) {
312
300
if (log.weightUnitId != null ) {
@@ -327,6 +315,7 @@ class RoutinesProvider with ChangeNotifier {
327
315
_routines.add (routine);
328
316
}
329
317
318
+ setActiveRoutine ();
330
319
notifyListeners ();
331
320
return routine;
332
321
}
0 commit comments