fixed ingredient weight validation #1017
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #721
Summary
When adding a new ingredient to a meal or logging it to the diary, entering a
decimal weight less than 1 (for example
0.5) caused the backend to reject therequest with the validation error “Ensure this value is greater than or equal
to 1.” The app did not handle this case and the page was popped without saving
the ingredient, which matched the bug report in #721.
This PR adds client-side validation to the weight field in the nutrition

ingredient form so invalid values are rejected before the request is sent, and
the user sees a clear error message instead of the page closing.
Proposed Changes
IngredientForminlib/widgets/nutrition/forms.dart:field-weightTextFormField.weight >= 1,field and the form is not submitted.
NutritionPlansProvider.addMealItemand the backend no longer throws avalidation exception.
Testing
Manual testing on iOS simulator:
Original failing case:
0.5in the weight field.No exception is thrown and no request is sent.
Valid integer weight:
50in the weight field and press Save.is added as expected. No errors in the console.
Other invalid inputs:
abc) → shows “Enter a valid number.”0or other values< 1→ shows “Weight must be at least 1.”1.5→ shows “Please enter a whole number.”Related Issue(s)
#721
If applicable, please link to any related issues (
Closes #123,Closes wger-project/other-repo#123,See also #123, etc.)Please check that the PR fulfills these requirements
(run
dart format .)///).