fixed ingredient weight validation

This commit is contained in:
Diya Hituvalli
2025-12-02 15:46:48 -05:00
parent e82efb2019
commit 41160d2a6e

View File

@@ -283,11 +283,18 @@ class IngredientFormState extends State<IngredientForm> {
_mealItem.amount = numberFormat.parse(value!);
},
validator: (value) {
try {
numberFormat.parse(value!);
} catch (error) {
final text = value?.trim() ?? '';
if (text.isEmpty) {
return 'Please enter a weight.';
}
final parsed = double.tryParse(text);
if (parsed == null) {
return AppLocalizations.of(context).enterValidNumber;
}
// Must be at least 1
if (parsed < 1) {
return 'Weight must be at least 1.';
}
return null;
},
),