From 8f7fb744aa07c1887cd3091c5e5f8abb1342c45d Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Mon, 5 Apr 2021 18:36:14 +0200 Subject: [PATCH] Make form for workout day scrollable --- lib/l10n/app_en.arb | 3 +- lib/widgets/workouts/forms.dart | 116 +++++++++--------- lib/widgets/workouts/workout_plan_detail.dart | 1 + 3 files changed, 61 insertions(+), 59 deletions(-) diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index dbe05122..0199bc61 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -107,6 +107,7 @@ "@set": { "description": "A set in a workout plan" }, + "dayDescriptionHelp": "A description of what is done on this day (e.g. 'pull day') or what body parts are trained (e.g. 'chest and shoulders')", "setNr": "Set {nr}", "@setNr": { "description": "Header in form indicating the number of the current set. Can also be translated as something like 'Set Nr. xy'.", @@ -115,7 +116,7 @@ "nr": {} } }, - "sameRepetitions": "If you do the same repetitions and weight for all sets you can just fill in one row. For example for 4 sets just enter one \"10\" for the repetitions, this automatically becomes \"4 x 10\".", + "sameRepetitions": "If you do the same repetitions and weight for all sets you can just fill in one row. For example for 4 sets just enter 10 for the repetitions, this automatically becomes \"4 x 10\".", "comment": "Comment", "@comment": { "description": "Comment, additional information" diff --git a/lib/widgets/workouts/forms.dart b/lib/widgets/workouts/forms.dart index b824b403..e808e94f 100644 --- a/lib/widgets/workouts/forms.dart +++ b/lib/widgets/workouts/forms.dart @@ -144,67 +144,67 @@ class _DayFormWidgetState extends State { @override Widget build(BuildContext context) { - return Container( - margin: EdgeInsets.all(20), - child: Form( - key: _form, - child: Column( - children: [ - TextFormField( - decoration: InputDecoration(labelText: AppLocalizations.of(context)!.description), - controller: widget.dayController, - onSaved: (value) { - widget._day.description = value!; - }, - validator: (value) { - const minLength = 5; - const maxLength = 100; - if (value!.isEmpty || value.length < minLength || value.length > maxLength) { - return AppLocalizations.of(context)!.enterCharacters(minLength, maxLength); - } - return null; - }, + return Form( + key: _form, + child: ListView( + children: [ + TextFormField( + decoration: InputDecoration( + labelText: AppLocalizations.of(context)!.description, + helperText: AppLocalizations.of(context)!.dayDescriptionHelp, + helperMaxLines: 2, ), - SizedBox(height: 10), - Text('Week days'), - ...Day.weekdays.keys.map((dayNr) => DayCheckbox(dayNr, widget._day)).toList(), - ElevatedButton( - child: Text(AppLocalizations.of(context)!.save), - onPressed: () async { - if (!_form.currentState!.validate()) { - return; - } - _form.currentState!.save(); + controller: widget.dayController, + onSaved: (value) { + widget._day.description = value!; + }, + validator: (value) { + const minLength = 5; + const maxLength = 100; + if (value!.isEmpty || value.length < minLength || value.length > maxLength) { + return AppLocalizations.of(context)!.enterCharacters(minLength, maxLength); + } + return null; + }, + ), + SizedBox(height: 10), + ...Day.weekdays.keys.map((dayNr) => DayCheckbox(dayNr, widget._day)).toList(), + ElevatedButton( + child: Text(AppLocalizations.of(context)!.save), + onPressed: () async { + if (!_form.currentState!.validate()) { + return; + } + _form.currentState!.save(); - try { - Provider.of(context, listen: false).addDay( - widget._day, - widget.workout, - ); + try { + Provider.of(context, listen: false).addDay( + widget._day, + widget.workout, + ); - widget.dayController.clear(); - Navigator.of(context).pop(); - } catch (error) { - await showDialog( - context: context, - builder: (ctx) => AlertDialog( - title: Text('An error occurred!'), - content: Text('Something went wrong.'), - actions: [ - TextButton( - child: Text('Okay'), - onPressed: () { - Navigator.of(ctx).pop(); - }, - ) - ], - ), - ); - } - }, - ), - ], - ), + widget.dayController.clear(); + Navigator.of(context).pop(); + } catch (error) { + await showDialog( + context: context, + builder: (ctx) => AlertDialog( + title: Text('An error occurred!'), + content: Text('Something went wrong.'), + actions: [ + TextButton( + child: Text('Okay'), + onPressed: () { + Navigator.of(ctx).pop(); + }, + ) + ], + ), + ); + } + }, + ), + ], ), ); } diff --git a/lib/widgets/workouts/workout_plan_detail.dart b/lib/widgets/workouts/workout_plan_detail.dart index 205eb418..27d486a8 100644 --- a/lib/widgets/workouts/workout_plan_detail.dart +++ b/lib/widgets/workouts/workout_plan_detail.dart @@ -65,6 +65,7 @@ class _WorkoutPlanDetailState extends State { arguments: FormScreenArguments( AppLocalizations.of(context)!.newDay, DayFormWidget(widget._workoutPlan), + true, ), ); },