Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandgeider committed Nov 17, 2024
1 parent aa6468e commit 7794948
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 109 deletions.
26 changes: 15 additions & 11 deletions lib/widgets/routines/app_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,21 @@ class RoutineListAppBar extends StatelessWidget implements PreferredSizeWidget {

@override
Widget build(BuildContext context) {
final i18n = AppLocalizations.of(context);

return AppBar(
title: Text(AppLocalizations.of(context).labelWorkoutPlans),
title: Text(i18n.labelWorkoutPlans),
actions: [
PopupMenuButton(
itemBuilder: (context) {
return [
PopupMenuItem<_RoutineAppBarOptions>(
value: _RoutineAppBarOptions.list,
child: Text(AppLocalizations.of(context).exerciseList),
child: Text(i18n.exerciseList),
),
PopupMenuItem<_RoutineAppBarOptions>(
value: _RoutineAppBarOptions.contribute,
child: Text(AppLocalizations.of(context).contributeExercise),
child: Text(i18n.contributeExercise),
),
];
},
Expand Down Expand Up @@ -85,31 +87,34 @@ class RoutineDetailAppBar extends StatelessWidget implements PreferredSizeWidget

@override
Widget build(BuildContext context) {
final i18n = AppLocalizations.of(context);
final provider = context.read<RoutinesProvider>();

return AppBar(
title: Text(routine.name),
actions: [
PopupMenuButton(
itemBuilder: (context) {
return [
PopupMenuItem<_RoutineDetailBarOptions>(
const PopupMenuItem<_RoutineDetailBarOptions>(
value: _RoutineDetailBarOptions.reload,
child: Text('debug / reload'),
),
PopupMenuItem<_RoutineDetailBarOptions>(
value: _RoutineDetailBarOptions.logs,
child: Text(AppLocalizations.of(context).labelWorkoutLogs),
child: Text(i18n.labelWorkoutLogs),
),
PopupMenuItem<_RoutineDetailBarOptions>(
value: _RoutineDetailBarOptions.edit,
child: Text(AppLocalizations.of(context).edit),
child: Text(i18n.edit),
),
PopupMenuItem<_RoutineDetailBarOptions>(
value: _RoutineDetailBarOptions.delete,
child: Text(AppLocalizations.of(context).delete),
child: Text(i18n.delete),
),
];
},
onSelected: (value) {
onSelected: (value) async {
switch (value) {
case _RoutineDetailBarOptions.edit:
Navigator.pushNamed(
Expand All @@ -126,12 +131,11 @@ class RoutineDetailAppBar extends StatelessWidget implements PreferredSizeWidget
);

case _RoutineDetailBarOptions.delete:
Provider.of<RoutinesProvider>(context, listen: false).deleteRoutine(routine.id!);
provider.deleteRoutine(routine.id!);
Navigator.of(context).pop();

case _RoutineDetailBarOptions.reload:
Provider.of<RoutinesProvider>(context, listen: false)
.fetchAndSetRoutineFull(routine.id!);
await provider.fetchAndSetRoutineFull(routine.id!);
}
},
),
Expand Down
45 changes: 10 additions & 35 deletions lib/widgets/routines/day.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,15 @@ import 'package:wger/widgets/core/core.dart';
import 'package:wger/widgets/exercises/exercises.dart';
import 'package:wger/widgets/exercises/images.dart';

class SettingWidget extends StatelessWidget {
class SetConfigDataWidget extends StatelessWidget {
final SetConfigData setConfigData;
final bool expanded;
final Function toggle;

const SettingWidget({
required this.setConfigData,
required this.expanded,
required this.toggle,
});
const SetConfigDataWidget({required this.setConfigData});

@override
Widget build(BuildContext context) {
final languageCode = Localizations.localeOf(context).languageCode;

return ListTile(
leading: InkWell(
child: SizedBox(
Expand All @@ -50,9 +46,7 @@ class SettingWidget extends StatelessWidget {
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text(setConfigData.exercise
.getExercise(Localizations.localeOf(context).languageCode)
.name),
title: Text(setConfigData.exercise.getExercise(languageCode).name),
content: ExerciseDetail(setConfigData.exercise),
actions: [
TextButton(
Expand All @@ -69,42 +63,23 @@ class SettingWidget extends StatelessWidget {
);
},
),
title: Text(
setConfigData.exercise.getExercise(Localizations.localeOf(context).languageCode).name,
),
title: Text(setConfigData.exercise.getExercise(languageCode).name),
subtitle: Text(setConfigData.textRepr),
);
}
}

class RoutineDayWidget extends StatefulWidget {
class RoutineDayWidget extends StatelessWidget {
final DayData _dayData;

const RoutineDayWidget(this._dayData);

@override
_RoutineDayWidgetState createState() => _RoutineDayWidgetState();
}

class _RoutineDayWidgetState extends State<RoutineDayWidget> {
bool _editing = true;

void _toggleExpanded() {
setState(() {
_editing = !_editing;
});
}

Widget getSlotDataRow(SlotData slotData) {
return Column(
children: [
if (slotData.comment.isNotEmpty) MutedText(slotData.comment),
...slotData.setConfigs.map(
(setting) => SettingWidget(
setConfigData: setting,
expanded: _editing,
toggle: _toggleExpanded,
),
(setting) => SetConfigDataWidget(setConfigData: setting),
),
// const Divider(),
],
Expand All @@ -120,8 +95,8 @@ class _RoutineDayWidgetState extends State<RoutineDayWidget> {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
DayHeader(day: widget._dayData),
...widget._dayData.slots.map((e) => getSlotDataRow(e)).toList(),
DayHeader(day: _dayData),
..._dayData.slots.map((e) => getSlotDataRow(e)).toList(),
],
),
),
Expand Down
22 changes: 10 additions & 12 deletions lib/widgets/routines/forms/day.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ class ReorderableDaysList extends StatefulWidget {
});

void _showDeleteConfirmationDialog(BuildContext context, Day day) {
final i18n = AppLocalizations.of(context);

showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text(AppLocalizations.of(context).delete),
content: Text(AppLocalizations.of(context).confirmDelete(day.name)),
title: Text(i18n.delete),
content: Text(i18n.confirmDelete(day.isRest ? i18n.restDay : day.name)),
actions: [
TextButton(
onPressed: () {
Expand All @@ -37,7 +39,7 @@ class ReorderableDaysList extends StatefulWidget {
TextButton(
onPressed: () async {
days.remove(day);
await Provider.of<RoutinesProvider>(context, listen: false).deleteDay(day.id!);
await context.read<RoutinesProvider>().deleteDay(day.id!);
Navigator.of(context).pop();
},
child: const Text('Delete'),
Expand Down Expand Up @@ -88,19 +90,15 @@ class _ReorderableDaysListState extends State<ReorderableDaysList> {
mainAxisSize: MainAxisSize.min,
children: [
IconButton(
onPressed: () {
widget.onDaySelected(day.id!);
},
onPressed: () => widget.onDaySelected(day.id!),
icon: isDaySelected ? const Icon(Icons.edit_off) : const Icon(Icons.edit),
),
IconButton(
icon: const Icon(Icons.delete),
onPressed: () {
widget._showDeleteConfirmationDialog(
context,
day,
); // Call the dialog function
},
onPressed: () => widget._showDeleteConfirmationDialog(
context,
day,
),
),
],
),
Expand Down
96 changes: 45 additions & 51 deletions lib/widgets/routines/gym_mode.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import 'package:wger/providers/exercises.dart';
import 'package:wger/providers/routines.dart';
import 'package:wger/theme/theme.dart';
import 'package:wger/widgets/core/core.dart';
import 'package:wger/widgets/core/progress_indicator.dart';
import 'package:wger/widgets/exercises/images.dart';
import 'package:wger/widgets/routines/forms/reps_unit.dart';
import 'package:wger/widgets/routines/forms/rir.dart';
Expand Down Expand Up @@ -451,59 +452,52 @@ class _LogPageState extends State<LogPage> {
},
),
ElevatedButton(
onPressed: _isSaving
? null
: () async {
// Validate and save the current values to the weightEntry
final isValid = _form.currentState!.validate();
if (!isValid) {
return;
}
_isSaving = true;
_form.currentState!.save();

// Save the entry on the server
try {
await Provider.of<RoutinesProvider>(
context,
listen: false,
).addLog(widget._log);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
duration: const Duration(seconds: 2), // default is 4
content: Text(
AppLocalizations.of(context).successfullySaved,
textAlign: TextAlign.center,
),
),
);
widget._controller.nextPage(
duration: DEFAULT_ANIMATION_DURATION,
curve: DEFAULT_ANIMATION_CURVE,
);
_isSaving = false;
} on WgerHttpException catch (error) {
if (mounted) {
showHttpExceptionErrorDialog(error, context);
onPressed: _isSaving
? null
: () async {
// Validate and save the current values to the weightEntry
final isValid = _form.currentState!.validate();
if (!isValid) {
return;
}
_isSaving = false;
} catch (error) {
if (mounted) {
showErrorDialog(error, context);
_isSaving = true;
_form.currentState!.save();

// Save the entry on the server
try {
await Provider.of<RoutinesProvider>(
context,
listen: false,
).addLog(widget._log);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
duration: const Duration(seconds: 2), // default is 4
content: Text(
AppLocalizations.of(context).successfullySaved,
textAlign: TextAlign.center,
),
),
);
widget._controller.nextPage(
duration: DEFAULT_ANIMATION_DURATION,
curve: DEFAULT_ANIMATION_CURVE,
);
_isSaving = false;
} on WgerHttpException catch (error) {
if (mounted) {
showHttpExceptionErrorDialog(error, context);
}
_isSaving = false;
} catch (error) {
if (mounted) {
showErrorDialog(error, context);
}
_isSaving = false;
}
_isSaving = false;
}
},
child: (!_isSaving)
? Text(AppLocalizations.of(context).save)
: const SizedBox(
height: 20,
width: 20,
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
),
),
),
},
child: _isSaving
? const FormProgressIndicator()
: Text(AppLocalizations.of(context).save)),
],
),
);
Expand Down

0 comments on commit 7794948

Please sign in to comment.