mirror of
https://github.com/wger-project/flutter.git
synced 2026-02-18 00:17:48 +01:00
Make form for workout day scrollable
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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();
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -65,6 +65,7 @@ class _WorkoutPlanDetailState extends State<WorkoutPlanDetail> {
|
||||
arguments: FormScreenArguments(
|
||||
AppLocalizations.of(context)!.newDay,
|
||||
DayFormWidget(widget._workoutPlan),
|
||||
true,
|
||||
),
|
||||
);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user