diff --git a/lib/widgets/nutrition/forms.dart b/lib/widgets/nutrition/forms.dart index 5d4b21d5..f5b2e7c1 100644 --- a/lib/widgets/nutrition/forms.dart +++ b/lib/widgets/nutrition/forms.dart @@ -157,10 +157,10 @@ class IngredientForm extends StatefulWidget { }); @override - State createState() => _IngredientFormState(); + State createState() => IngredientFormState(); } -class _IngredientFormState extends State { +class IngredientFormState extends State { final _form = GlobalKey(); final _ingredientController = TextEditingController(); final _ingredientIdController = TextEditingController(); @@ -209,7 +209,10 @@ class _IngredientFormState extends State { onFieldSubmitted: (_) {}, onChanged: (value) { setState(() { - _mealItem.amount = double.tryParse(value) ?? _mealItem.amount; + final v = double.tryParse(value); + if (v != null) { + _mealItem.amount = v; + } }); }, onSaved: (value) { diff --git a/test/nutrition/nutritional_meal_item_form_test.dart b/test/nutrition/nutritional_meal_item_form_test.dart index 2a751a6d..aa739ba1 100644 --- a/test/nutrition/nutritional_meal_item_form_test.dart +++ b/test/nutrition/nutritional_meal_item_form_test.dart @@ -213,7 +213,7 @@ void main() { testWidgets('confirm found ingredient dialog', (WidgetTester tester) async { await tester.pumpWidget(createMealItemFormScreen(meal1, '123', true)); - final IngredientForm formScreen = tester.widget(find.byType(IngredientForm)); + final IngredientFormState formState = tester.state(find.byType(IngredientForm)); await tester.tap(find.byKey(const Key('scan-button'))); await tester.pumpAndSettle(); @@ -223,7 +223,7 @@ void main() { await tester.tap(find.byKey(const Key('found-dialog-confirm-button'))); await tester.pumpAndSettle(); - expect(formScreen.ingredientIdController.text, '1'); + expect(formState.ingredientIdController.text, '1'); }); testWidgets('close found ingredient dialog', (WidgetTester tester) async { @@ -293,7 +293,7 @@ void main() { (WidgetTester tester) async { await tester.pumpWidget(createMealItemFormScreen(meal1, '123', true)); - final IngredientForm formScreen = tester.widget(find.byType(IngredientForm)); + final IngredientFormState formState = tester.state(find.byType(IngredientForm)); await tester.tap(find.byKey(const Key('scan-button'))); await tester.pumpAndSettle(); @@ -303,7 +303,7 @@ void main() { await tester.tap(find.byKey(const Key('found-dialog-confirm-button'))); await tester.pumpAndSettle(); - expect(formScreen.ingredientIdController.text, '1'); + expect(formState.ingredientIdController.text, '1'); await tester.enterText(find.byKey(const Key('field-weight')), '2'); await tester.pumpAndSettle(); @@ -313,7 +313,7 @@ void main() { await tester.tap(find.byKey(const Key(SUBMIT_BUTTON_KEY_NAME))); await tester.pumpAndSettle(); - expect(formScreen.mealItem.amount, 2); + expect(formState.mealItem.amount, 2); verify(mockNutrition.addMealItem(any, meal1)); });