From 04e112d8106426783396a99a93fe14317a763d56 Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Wed, 20 Nov 2024 14:39:17 +0100 Subject: [PATCH] Fix some widgets, polishing, renaming --- lib/l10n/app_en.arb | 4 ++-- lib/providers/routines.dart | 5 ++++- lib/screens/routine_screen.dart | 22 ++++++++++++------- lib/widgets/routines/day.dart | 2 +- lib/widgets/routines/routine_detail.dart | 4 +++- lib/widgets/routines/workout_plans_list.dart | 20 +++++++++-------- .../exercises/exercisebaseinfo_response.json | 2 +- 7 files changed, 36 insertions(+), 23 deletions(-) diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index bab70e0b..7cdbf84e 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -207,7 +207,7 @@ }, "restDay": "Rest day", "isRestDay": "Is rest day", - "isRestDayHelp": "Please consider that all sets are removed from rest days when saved", + "isRestDayHelp": "Please consider that all sets are removed from rest days when the form is saved", "routineDays": "Days in routine", "resultingRoutine": "Resulting routine", "newDay": "New day", @@ -710,7 +710,7 @@ "fitInWeekHelp": "Select if you want to fit the workout days into a week, you can add e.g. three days and mark this checkbox.", "addSuperset": "Add superset", "setHasProgression": "Set has progression", - "setHasProgressionWarning": "Please note that at the moment it is not possible to edit all settings for a set on the mobile application or configure the progression. ", + "setHasProgressionWarning": "Please note that at the moment it is not possible to edit all settings for a set on the mobile application or configure automatic progression. For now, please use the web application.", "setHasNoExercises": "This set has no exercises yet!", "contributeExercise": "Contribute an exercise", "translation": "Translation", diff --git a/lib/providers/routines.dart b/lib/providers/routines.dart index 9df751ee..055816cc 100644 --- a/lib/providers/routines.dart +++ b/lib/providers/routines.dart @@ -299,7 +299,8 @@ class RoutinesProvider with ChangeNotifier { // ... and done final routineIndex = _routines.indexWhere((r) => r.id == routineId); - _routines.replaceRange(routineIndex, routineIndex + 1, [routine]); + _routines[routineIndex] = routine; + // _routines.replaceRange(routineIndex, routineIndex + 1, [routine]); notifyListeners(); return routine; @@ -321,6 +322,8 @@ class RoutinesProvider with ChangeNotifier { routine.toJson(), baseProvider.makeUrl(_routinesUrlPath, id: routine.id), ); + await fetchAndSetRoutineFull(routine.id!); + notifyListeners(); } diff --git a/lib/screens/routine_screen.dart b/lib/screens/routine_screen.dart index eba313de..e29999d9 100644 --- a/lib/screens/routine_screen.dart +++ b/lib/screens/routine_screen.dart @@ -29,25 +29,31 @@ class RoutineScreen extends StatelessWidget { static const routeName = '/routine-detail'; - Future _loadFullWorkout(BuildContext context, int routineId) { - return Provider.of(context, listen: false).fetchAndSetRoutineFull(routineId); - } - @override Widget build(BuildContext context) { - final routine = ModalRoute.of(context)!.settings.arguments as Routine; + final routineArgs = ModalRoute.of(context)!.settings.arguments as Routine; + final provider = context.read(); return Scaffold( - appBar: RoutineDetailAppBar(routine), + appBar: RoutineDetailAppBar(routineArgs), + body: SingleChildScrollView( + child: Consumer( + builder: (context, value, child) => RoutineDetail(routineArgs), + ), + ), + ); + + return Scaffold( + appBar: RoutineDetailAppBar(routineArgs), body: FutureBuilder( - future: _loadFullWorkout(context, routine.id!), + future: provider.fetchAndSetRoutineFull(routineArgs.id!), builder: (context, snapshot) => ListView( children: [ if (snapshot.connectionState == ConnectionState.waiting) const BoxedProgressIndicator() else Consumer( - builder: (context, value, child) => RoutineDetail(routine), + builder: (context, value, child) => RoutineDetail(snapshot.data!), ), ], ), diff --git a/lib/widgets/routines/day.dart b/lib/widgets/routines/day.dart index 745a76f1..f677e211 100644 --- a/lib/widgets/routines/day.dart +++ b/lib/widgets/routines/day.dart @@ -96,7 +96,7 @@ class RoutineDayWidget extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.start, children: [ DayHeader(day: _dayData), - ..._dayData.slots.map((e) => getSlotDataRow(e)).toList(), + ..._dayData.slots.map((e) => getSlotDataRow(e)), ], ), ), diff --git a/lib/widgets/routines/routine_detail.dart b/lib/widgets/routines/routine_detail.dart index 4e9ee01e..a89308a5 100644 --- a/lib/widgets/routines/routine_detail.dart +++ b/lib/widgets/routines/routine_detail.dart @@ -36,7 +36,9 @@ class RoutineDetail extends StatelessWidget { padding: const EdgeInsets.all(15), child: Text(_routine.description), ), - ..._routine.dayDataCurrentIteration.map((dayData) => RoutineDayWidget(dayData)), + ..._routine.dayDataCurrentIteration + .where((dayData) => dayData.day != null) + .map((dayData) => RoutineDayWidget(dayData)), ], ); } diff --git a/lib/widgets/routines/workout_plans_list.dart b/lib/widgets/routines/workout_plans_list.dart index 34e7d199..19025a41 100644 --- a/lib/widgets/routines/workout_plans_list.dart +++ b/lib/widgets/routines/workout_plans_list.dart @@ -25,31 +25,33 @@ import 'package:wger/screens/routine_screen.dart'; import 'package:wger/widgets/core/text_prompt.dart'; class WorkoutPlansList extends StatelessWidget { - final RoutinesProvider _workoutProvider; + final RoutinesProvider _routineProvider; - const WorkoutPlansList(this._workoutProvider); + const WorkoutPlansList(this._routineProvider); @override Widget build(BuildContext context) { return RefreshIndicator( - onRefresh: () => _workoutProvider.fetchAndSetAllRoutinesFull(), + onRefresh: () => _routineProvider.fetchAndSetAllRoutinesFull(), // onRefresh: () => _workoutProvider.fetchAndSetAllPlansSparse(), - child: _workoutProvider.items.isEmpty + child: _routineProvider.items.isEmpty ? const TextPrompt() : ListView.builder( padding: const EdgeInsets.all(10.0), - itemCount: _workoutProvider.items.length, + itemCount: _routineProvider.items.length, itemBuilder: (context, index) { - final currentWorkout = _workoutProvider.items[index]; + final currentWorkout = _routineProvider.items[index]; return Card( child: ListTile( - onTap: () { - _workoutProvider.setCurrentPlan(currentWorkout.id!); + onTap: () async { + _routineProvider.setCurrentPlan(currentWorkout.id!); + final routine = + await _routineProvider.fetchAndSetRoutineFull(currentWorkout.id!); Navigator.of(context).pushNamed( RoutineScreen.routeName, - arguments: currentWorkout, + arguments: routine, ); }, title: Text(currentWorkout.name), diff --git a/test/fixtures/exercises/exercisebaseinfo_response.json b/test/fixtures/exercises/exercisebaseinfo_response.json index 7076d729..46d5ac7c 100644 --- a/test/fixtures/exercises/exercisebaseinfo_response.json +++ b/test/fixtures/exercises/exercisebaseinfo_response.json @@ -121,7 +121,7 @@ "license_author": null } ], - "exercises": [ + "translations": [ { "id": 345, "uuid": "c788d643-150a-4ac7-97ef-84643c6419bf",