This commit is contained in:
Patrick Witter
2021-08-29 10:15:29 -05:00
parent b23c417da5
commit 0c2e57ef66

View File

@@ -35,7 +35,8 @@ class WeightForm extends StatelessWidget {
WeightForm([WeightEntry? weightEntry]) {
this._weightEntry = weightEntry ?? WeightEntry(date: DateTime.now());
weightController.text = _weightEntry.id == null ? '' : _weightEntry.weight.toString();
weightController.text =
_weightEntry.id == null ? '' : _weightEntry.weight.toString();
dateController.text = toDate(_weightEntry.date)!;
}
@@ -47,12 +48,13 @@ class WeightForm extends StatelessWidget {
children: [
// Weight date
TextFormField(
decoration: InputDecoration(labelText: AppLocalizations.of(context).date),
decoration:
InputDecoration(labelText: AppLocalizations.of(context).date),
controller: dateController,
onTap: () async {
// Stop keyboard from appearing
FocusScope.of(context).requestFocus(new FocusNode());
print("date picker");
// Show Date Picker Here
var pickedDate = await showDatePicker(
context: context,
@@ -66,7 +68,8 @@ class WeightForm extends StatelessWidget {
}
// if the date is known, don't allow it
return Provider.of<BodyWeightProvider>(context, listen: false).findByDate(day) ==
return Provider.of<BodyWeightProvider>(context, listen: false)
.findByDate(day) ==
null
? true
: false;
@@ -82,7 +85,8 @@ class WeightForm extends StatelessWidget {
// Weight
TextFormField(
decoration: InputDecoration(labelText: AppLocalizations.of(context).weight),
decoration:
InputDecoration(labelText: AppLocalizations.of(context).weight),
controller: weightController,
keyboardType: TextInputType.number,
onSaved: (newValue) {
@@ -113,12 +117,25 @@ class WeightForm extends StatelessWidget {
// Save the entry on the server
try {
_weightEntry.id == null
? await Provider.of<BodyWeightProvider>(context, listen: false)
? await Provider.of<BodyWeightProvider>(context,
listen: false)
.addEntry(_weightEntry)
: await Provider.of<BodyWeightProvider>(context, listen: false)
: await Provider.of<BodyWeightProvider>(context,
listen: false)
.editEntry(_weightEntry);
} on WgerHttpException catch (error) {
await showDialog(
context: context,
builder: (context) => AlertDialog(
content: Text("please wait"),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: Text("Ok"))
],
));
showHttpExceptionErrorDialog(error, context);
Navigator.pop(context);
} catch (error) {
showErrorDialog(error, context);
}