Make form for workout day scrollable

This commit is contained in:
Roland Geider
2021-04-05 18:36:14 +02:00
parent 2985077683
commit 8f7fb744aa
3 changed files with 61 additions and 59 deletions

View File

@@ -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"

View File

@@ -144,67 +144,67 @@ class _DayFormWidgetState extends State<DayFormWidget> {
@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<WorkoutPlans>(context, listen: false).addDay(
widget._day,
widget.workout,
);
try {
Provider.of<WorkoutPlans>(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();
},
)
],
),
);
}
},
),
],
),
);
}

View File

@@ -65,6 +65,7 @@ class _WorkoutPlanDetailState extends State<WorkoutPlanDetail> {
arguments: FormScreenArguments(
AppLocalizations.of(context)!.newDay,
DayFormWidget(widget._workoutPlan),
true,
),
);
},