mirror of
https://github.com/wger-project/flutter.git
synced 2026-02-18 00:17:48 +01:00
Allow to add weight entries from the dashboard
This commit is contained in:
@@ -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),
|
||||
],
|
||||
),
|
||||
],
|
||||
|
||||
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user