[fiber] default to 0

This commit is contained in:
doman 2023-10-27 14:09:38 +02:00
parent 5d0743a276
commit 5a893f80f0

View file

@ -43,11 +43,13 @@ class _AddProductScreen extends State<AddProductScreen> {
); );
} }
Future<double?> _parseDouble(String text, String name) async { Future<double?> _parseDouble(String text, String name, {bool silent = false}) async {
try { try {
return double.parse(text.replaceAll(",", ".")); return double.parse(text.replaceAll(",", "."));
} catch (e) { } catch (e) {
showError("$name must be a number"); if (!silent) {
showError("$name must be a number");
}
return null; return null;
} }
} }
@ -56,9 +58,9 @@ class _AddProductScreen extends State<AddProductScreen> {
var carb = await _parseDouble(carbController.text, "Carbs"); var carb = await _parseDouble(carbController.text, "Carbs");
var fat = await _parseDouble(fatController.text, "Fat"); var fat = await _parseDouble(fatController.text, "Fat");
var protein = await _parseDouble(proteinController.text, "Protein"); var protein = await _parseDouble(proteinController.text, "Protein");
var fiber = await _parseDouble(fiberController.text, "Fiber"); var fiber = await _parseDouble(fiberController.text, "Fiber", silent: true) ?? 0;
if (carb == null || fat == null || protein == null || fiber == null) { if (carb == null || fat == null || protein == null) {
return; return;
} }