mirror of
https://github.com/wger-project/flutter.git
synced 2026-02-18 00:17:48 +01:00
Retrieve the current routine dynamically
This behaviour is now the same as the nutritional plans.
This commit is contained in:
@@ -24,8 +24,7 @@ import '../test_data/routines.dart';
|
||||
|
||||
Widget createDashboardScreen({locale = 'en'}) {
|
||||
final mockWorkoutProvider = MockRoutinesProvider();
|
||||
when(mockWorkoutProvider.activeRoutine)
|
||||
.thenReturn(getTestRoutine(exercises: getScreenshotExercises()));
|
||||
when(mockWorkoutProvider.items).thenReturn([getTestRoutine(exercises: getScreenshotExercises())]);
|
||||
|
||||
when(mockWorkoutProvider.fetchSessionData()).thenAnswer((a) => Future.value([
|
||||
WorkoutSession(
|
||||
|
||||
@@ -83,6 +83,15 @@ class RoutinesProvider with ChangeNotifier {
|
||||
_repetitionUnits = repetitionUnits ?? [];
|
||||
}
|
||||
|
||||
/// Returns the current active nutritional plan. At the moment this is just
|
||||
/// the latest, but this might change in the future.
|
||||
Routine? get currentRoutine {
|
||||
if (_routines.isNotEmpty) {
|
||||
return _routines.first;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
List<Routine> get items {
|
||||
return [..._routines];
|
||||
}
|
||||
@@ -97,7 +106,6 @@ class RoutinesProvider with ChangeNotifier {
|
||||
|
||||
/// Clears all lists
|
||||
void clear() {
|
||||
activeRoutine = null;
|
||||
_routines = [];
|
||||
_weightUnits = [];
|
||||
_repetitionUnits = [];
|
||||
@@ -138,16 +146,6 @@ class RoutinesProvider with ChangeNotifier {
|
||||
return _routines.indexWhere((routine) => routine.id == id);
|
||||
}
|
||||
|
||||
/// Sets the current active routine. At the moment this is just the latest,
|
||||
/// but this might change in the future.
|
||||
void setActiveRoutine() {
|
||||
if (_routines.isNotEmpty) {
|
||||
activeRoutine = _routines.first;
|
||||
} else {
|
||||
activeRoutine = null;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Routines
|
||||
*/
|
||||
@@ -165,7 +163,6 @@ class RoutinesProvider with ChangeNotifier {
|
||||
await fetchAndSetRoutineFull(entry['id']);
|
||||
}
|
||||
|
||||
setActiveRoutine();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@@ -181,7 +178,6 @@ class RoutinesProvider with ChangeNotifier {
|
||||
_routines.add(plan);
|
||||
}
|
||||
|
||||
setActiveRoutine();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@@ -220,7 +216,6 @@ class RoutinesProvider with ChangeNotifier {
|
||||
_routines.add(routine);
|
||||
_routines.sort((a, b) => b.created.compareTo(a.created));
|
||||
|
||||
setActiveRoutine();
|
||||
notifyListeners();
|
||||
return routine;
|
||||
}
|
||||
@@ -338,7 +333,6 @@ class RoutinesProvider with ChangeNotifier {
|
||||
_routines.add(routine);
|
||||
}
|
||||
|
||||
setActiveRoutine();
|
||||
notifyListeners();
|
||||
return routine;
|
||||
}
|
||||
|
||||
@@ -116,8 +116,8 @@ class _HomeTabsScreenState extends State<HomeTabsScreen> with SingleTickerProvid
|
||||
|
||||
// Current routine
|
||||
widget._logger.info('Loading current routine');
|
||||
if (routinesProvider.activeRoutine != null) {
|
||||
final planId = routinesProvider.activeRoutine!.id!;
|
||||
if (routinesProvider.currentRoutine != null) {
|
||||
final planId = routinesProvider.currentRoutine!.id!;
|
||||
await routinesProvider.fetchAndSetRoutineFull(planId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ class _DashboardRoutineWidgetState extends State<DashboardRoutineWidget> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final routine = context.watch<RoutinesProvider>().activeRoutine;
|
||||
final routine = context.watch<RoutinesProvider>().currentRoutine;
|
||||
_hasContent = routine != null;
|
||||
final dateFormat = DateFormat.yMd(Localizations.localeOf(context).languageCode);
|
||||
|
||||
|
||||
@@ -53,8 +53,6 @@ class _RoutinesListState extends State<RoutinesList> {
|
||||
return Card(
|
||||
child: ListTile(
|
||||
onTap: () async {
|
||||
widget._routineProvider.activeRoutine = currentRoutine;
|
||||
|
||||
setState(() {
|
||||
_loadingRoutine = currentRoutine.id;
|
||||
});
|
||||
|
||||
@@ -1554,5 +1554,5 @@ packages:
|
||||
source: hosted
|
||||
version: "3.1.3"
|
||||
sdks:
|
||||
dart: ">=3.8.0 <4.0.0"
|
||||
dart: ">=3.9.0 <4.0.0"
|
||||
flutter: ">=3.35.0"
|
||||
|
||||
@@ -294,15 +294,6 @@ class MockRoutinesProvider extends _i1.Mock implements _i12.RoutinesProvider {
|
||||
returnValue: 0,
|
||||
) as int);
|
||||
|
||||
@override
|
||||
void setActiveRoutine() => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#setActiveRoutine,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
_i13.Future<void> fetchAndSetAllRoutinesFull() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
|
||||
@@ -294,15 +294,6 @@ class MockRoutinesProvider extends _i1.Mock implements _i12.RoutinesProvider {
|
||||
returnValue: 0,
|
||||
) as int);
|
||||
|
||||
@override
|
||||
void setActiveRoutine() => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#setActiveRoutine,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
_i13.Future<void> fetchAndSetAllRoutinesFull() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
|
||||
@@ -294,15 +294,6 @@ class MockRoutinesProvider extends _i1.Mock implements _i12.RoutinesProvider {
|
||||
returnValue: 0,
|
||||
) as int);
|
||||
|
||||
@override
|
||||
void setActiveRoutine() => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#setActiveRoutine,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
_i13.Future<void> fetchAndSetAllRoutinesFull() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
|
||||
@@ -294,15 +294,6 @@ class MockRoutinesProvider extends _i1.Mock implements _i12.RoutinesProvider {
|
||||
returnValue: 0,
|
||||
) as int);
|
||||
|
||||
@override
|
||||
void setActiveRoutine() => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#setActiveRoutine,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
_i13.Future<void> fetchAndSetAllRoutinesFull() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
|
||||
@@ -294,15 +294,6 @@ class MockRoutinesProvider extends _i1.Mock implements _i12.RoutinesProvider {
|
||||
returnValue: 0,
|
||||
) as int);
|
||||
|
||||
@override
|
||||
void setActiveRoutine() => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#setActiveRoutine,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
_i13.Future<void> fetchAndSetAllRoutinesFull() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
|
||||
@@ -294,15 +294,6 @@ class MockRoutinesProvider extends _i1.Mock implements _i12.RoutinesProvider {
|
||||
returnValue: 0,
|
||||
) as int);
|
||||
|
||||
@override
|
||||
void setActiveRoutine() => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#setActiveRoutine,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
_i13.Future<void> fetchAndSetAllRoutinesFull() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
|
||||
@@ -294,15 +294,6 @@ class MockRoutinesProvider extends _i1.Mock implements _i12.RoutinesProvider {
|
||||
returnValue: 0,
|
||||
) as int);
|
||||
|
||||
@override
|
||||
void setActiveRoutine() => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#setActiveRoutine,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
_i13.Future<void> fetchAndSetAllRoutinesFull() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
|
||||
@@ -294,15 +294,6 @@ class MockRoutinesProvider extends _i1.Mock implements _i12.RoutinesProvider {
|
||||
returnValue: 0,
|
||||
) as int);
|
||||
|
||||
@override
|
||||
void setActiveRoutine() => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#setActiveRoutine,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
_i13.Future<void> fetchAndSetAllRoutinesFull() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
|
||||
@@ -294,15 +294,6 @@ class MockRoutinesProvider extends _i1.Mock implements _i12.RoutinesProvider {
|
||||
returnValue: 0,
|
||||
) as int);
|
||||
|
||||
@override
|
||||
void setActiveRoutine() => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#setActiveRoutine,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
_i13.Future<void> fetchAndSetAllRoutinesFull() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
|
||||
@@ -294,15 +294,6 @@ class MockRoutinesProvider extends _i1.Mock implements _i12.RoutinesProvider {
|
||||
returnValue: 0,
|
||||
) as int);
|
||||
|
||||
@override
|
||||
void setActiveRoutine() => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#setActiveRoutine,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
_i13.Future<void> fetchAndSetAllRoutinesFull() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
|
||||
Reference in New Issue
Block a user