Skip to content

Commit 4330e51

Browse files
committed
Retrieve the current routine dynamically
This behaviour is now the same as the nutritional plans.
1 parent 244468f commit 4330e51

16 files changed

+14
-113
lines changed

integration_test/1_dashboard.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ import '../test_data/routines.dart';
2424

2525
Widget createDashboardScreen({locale = 'en'}) {
2626
final mockWorkoutProvider = MockRoutinesProvider();
27-
when(mockWorkoutProvider.activeRoutine)
28-
.thenReturn(getTestRoutine(exercises: getScreenshotExercises()));
27+
when(mockWorkoutProvider.items).thenReturn([getTestRoutine(exercises: getScreenshotExercises())]);
2928

3029
when(mockWorkoutProvider.fetchSessionData()).thenAnswer((a) => Future.value([
3130
WorkoutSession(

lib/providers/routines.dart

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ class RoutinesProvider with ChangeNotifier {
8383
_repetitionUnits = repetitionUnits ?? [];
8484
}
8585

86+
/// Returns the current active nutritional plan. At the moment this is just
87+
/// the latest, but this might change in the future.
88+
Routine? get currentRoutine {
89+
if (_routines.isNotEmpty) {
90+
return _routines.first;
91+
}
92+
return null;
93+
}
94+
8695
List<Routine> get items {
8796
return [..._routines];
8897
}
@@ -97,7 +106,6 @@ class RoutinesProvider with ChangeNotifier {
97106

98107
/// Clears all lists
99108
void clear() {
100-
activeRoutine = null;
101109
_routines = [];
102110
_weightUnits = [];
103111
_repetitionUnits = [];
@@ -138,16 +146,6 @@ class RoutinesProvider with ChangeNotifier {
138146
return _routines.indexWhere((routine) => routine.id == id);
139147
}
140148

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() {
144-
if (_routines.isNotEmpty) {
145-
activeRoutine = _routines.first;
146-
} else {
147-
activeRoutine = null;
148-
}
149-
}
150-
151149
/*
152150
* Routines
153151
*/
@@ -165,7 +163,6 @@ class RoutinesProvider with ChangeNotifier {
165163
await fetchAndSetRoutineFull(entry['id']);
166164
}
167165

168-
setActiveRoutine();
169166
notifyListeners();
170167
}
171168

@@ -181,7 +178,6 @@ class RoutinesProvider with ChangeNotifier {
181178
_routines.add(plan);
182179
}
183180

184-
setActiveRoutine();
185181
notifyListeners();
186182
}
187183

@@ -220,7 +216,6 @@ class RoutinesProvider with ChangeNotifier {
220216
_routines.add(routine);
221217
_routines.sort((a, b) => b.created.compareTo(a.created));
222218

223-
setActiveRoutine();
224219
notifyListeners();
225220
return routine;
226221
}
@@ -338,7 +333,6 @@ class RoutinesProvider with ChangeNotifier {
338333
_routines.add(routine);
339334
}
340335

341-
setActiveRoutine();
342336
notifyListeners();
343337
return routine;
344338
}

lib/screens/home_tabs_screen.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ class _HomeTabsScreenState extends State<HomeTabsScreen> with SingleTickerProvid
116116

117117
// Current routine
118118
widget._logger.info('Loading current routine');
119-
if (routinesProvider.activeRoutine != null) {
120-
final planId = routinesProvider.activeRoutine!.id!;
119+
if (routinesProvider.currentRoutine != null) {
120+
final planId = routinesProvider.currentRoutine!.id!;
121121
await routinesProvider.fetchAndSetRoutineFull(planId);
122122
}
123123
}

lib/widgets/dashboard/widgets/routines.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class _DashboardRoutineWidgetState extends State<DashboardRoutineWidget> {
4444

4545
@override
4646
Widget build(BuildContext context) {
47-
final routine = context.watch<RoutinesProvider>().activeRoutine;
47+
final routine = context.watch<RoutinesProvider>().currentRoutine;
4848
_hasContent = routine != null;
4949
final dateFormat = DateFormat.yMd(Localizations.localeOf(context).languageCode);
5050

lib/widgets/routines/routines_list.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ class _RoutinesListState extends State<RoutinesList> {
5353
return Card(
5454
child: ListTile(
5555
onTap: () async {
56-
widget._routineProvider.activeRoutine = currentRoutine;
57-
5856
setState(() {
5957
_loadingRoutine = currentRoutine.id;
6058
});

pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1554,5 +1554,5 @@ packages:
15541554
source: hosted
15551555
version: "3.1.3"
15561556
sdks:
1557-
dart: ">=3.8.0 <4.0.0"
1557+
dart: ">=3.9.0 <4.0.0"
15581558
flutter: ">=3.35.0"

test/routine/day_form_test.mocks.dart

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -294,15 +294,6 @@ class MockRoutinesProvider extends _i1.Mock implements _i12.RoutinesProvider {
294294
returnValue: 0,
295295
) as int);
296296

297-
@override
298-
void setActiveRoutine() => super.noSuchMethod(
299-
Invocation.method(
300-
#setActiveRoutine,
301-
[],
302-
),
303-
returnValueForMissingStub: null,
304-
);
305-
306297
@override
307298
_i13.Future<void> fetchAndSetAllRoutinesFull() => (super.noSuchMethod(
308299
Invocation.method(

test/routine/forms/session_form_test.mocks.dart

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -294,15 +294,6 @@ class MockRoutinesProvider extends _i1.Mock implements _i12.RoutinesProvider {
294294
returnValue: 0,
295295
) as int);
296296

297-
@override
298-
void setActiveRoutine() => super.noSuchMethod(
299-
Invocation.method(
300-
#setActiveRoutine,
301-
[],
302-
),
303-
returnValueForMissingStub: null,
304-
);
305-
306297
@override
307298
_i13.Future<void> fetchAndSetAllRoutinesFull() => (super.noSuchMethod(
308299
Invocation.method(

test/routine/gym_mode_session_screen_test.mocks.dart

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -294,15 +294,6 @@ class MockRoutinesProvider extends _i1.Mock implements _i12.RoutinesProvider {
294294
returnValue: 0,
295295
) as int);
296296

297-
@override
298-
void setActiveRoutine() => super.noSuchMethod(
299-
Invocation.method(
300-
#setActiveRoutine,
301-
[],
302-
),
303-
returnValueForMissingStub: null,
304-
);
305-
306297
@override
307298
_i13.Future<void> fetchAndSetAllRoutinesFull() => (super.noSuchMethod(
308299
Invocation.method(

test/routine/repetition_unit_form_widget_test.mocks.dart

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -294,15 +294,6 @@ class MockRoutinesProvider extends _i1.Mock implements _i12.RoutinesProvider {
294294
returnValue: 0,
295295
) as int);
296296

297-
@override
298-
void setActiveRoutine() => super.noSuchMethod(
299-
Invocation.method(
300-
#setActiveRoutine,
301-
[],
302-
),
303-
returnValueForMissingStub: null,
304-
);
305-
306297
@override
307298
_i13.Future<void> fetchAndSetAllRoutinesFull() => (super.noSuchMethod(
308299
Invocation.method(

0 commit comments

Comments
 (0)