mirror of
https://github.com/wger-project/flutter.git
synced 2026-11-28 17:08:29 +01:00
fixed ingredient weight validation
This commit is contained in:
@@ -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;
|
||||
},
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user