Allow to add weight entries from the dashboard

This commit is contained in:
Roland Geider
2021-02-18 23:08:31 +01:00
parent bac2ef44f8
commit d101ec6bd3
2 changed files with 22 additions and 9 deletions

View File

@@ -28,8 +28,10 @@ import 'package:wger/providers/nutrition.dart';
import 'package:wger/providers/workout_plans.dart';
import 'package:wger/screens/nutritional_plan_screen.dart';
import 'package:wger/screens/workout_plan_screen.dart';
import 'package:wger/widgets/core/bottom_sheet.dart';
import 'package:wger/widgets/nutrition/charts.dart';
import 'package:wger/widgets/weight/charts.dart';
import 'package:wger/widgets/weight/forms.dart';
class DashboardNutritionWidget extends StatefulWidget {
const DashboardNutritionWidget({
@@ -153,15 +155,15 @@ class _DashboardWeightWidgetState extends State<DashboardWeightWidget> {
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
TextButton(
child: const Text('Action one'),
onPressed: () {},
child: Text(AppLocalizations.of(context).newEntry),
onPressed: () async {
showFormBottomSheet(
context,
AppLocalizations.of(context).newEntry,
WeightForm(),
);
},
),
const SizedBox(width: 8),
TextButton(
child: const Text('Action two'),
onPressed: () {},
),
const SizedBox(width: 8),
],
),
],

View File

@@ -17,7 +17,7 @@ class WeightForm extends StatelessWidget {
WeightForm([weightEntry]) {
this._weightEntry = weightEntry ?? WeightEntry();
weightController.text = _weightEntry.weight.toString();
weightController.text = _weightEntry.weight == null ? '' : _weightEntry.weight.toString();
}
@override
@@ -59,6 +59,17 @@ class WeightForm extends StatelessWidget {
onSaved: (newValue) {
_weightEntry.weight = double.parse(newValue);
},
validator: (value) {
if (value.isEmpty) {
return 'Please enter a weight';
}
try {
double.parse(value);
} catch (error) {
return 'Please enter a valid number';
}
return null;
},
),
ElevatedButton(
child: Text(AppLocalizations.of(context).save),