mirror of
https://github.com/wger-project/flutter.git
synced 2026-02-18 23:42:00 +01:00
Attempt1
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user