diff --git a/lib/screens/add_product.dart b/lib/screens/add_product.dart index b650d41..2468615 100644 --- a/lib/screens/add_product.dart +++ b/lib/screens/add_product.dart @@ -43,11 +43,13 @@ class _AddProductScreen extends State { ); } - Future _parseDouble(String text, String name) async { + Future _parseDouble(String text, String name, {bool silent = false}) async { try { return double.parse(text.replaceAll(",", ".")); } catch (e) { - showError("$name must be a number"); + if (!silent) { + showError("$name must be a number"); + } return null; } } @@ -56,9 +58,9 @@ class _AddProductScreen extends State { var carb = await _parseDouble(carbController.text, "Carbs"); var fat = await _parseDouble(fatController.text, "Fat"); 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; }