From 4cc78fb6574746932404d822303e4065dc6b0bba Mon Sep 17 00:00:00 2001 From: doman Date: Sat, 26 Aug 2023 22:56:43 +0200 Subject: [PATCH] [rename] pushMeDaddy [addEntry] add silent mode when selecting product --- lib/screens/add_entry.dart | 20 ++++++++++++-------- lib/screens/add_meal.dart | 4 ++-- lib/screens/add_product.dart | 4 ++-- lib/screens/edit_entry.dart | 6 +++--- lib/screens/login.dart | 6 +++--- lib/screens/register.dart | 4 ++-- 6 files changed, 24 insertions(+), 20 deletions(-) diff --git a/lib/screens/add_entry.dart b/lib/screens/add_entry.dart index 51ed1d3..43e5ada 100644 --- a/lib/screens/add_entry.dart +++ b/lib/screens/add_entry.dart @@ -31,7 +31,7 @@ class _AddEntryScreen extends State { super.dispose(); } - void popMeDady() { + void popMeDaddy() { Navigator.pop( context, ); @@ -63,23 +63,27 @@ class _AddEntryScreen extends State { ); } - Future _parseDouble(String text, String name) async { + Future _parseDouble(String text) async { try { return double.parse(text.replaceAll(",", ".")); } catch (e) { - showError("$name must be a number"); return null; } } - Future _addEntry() async { + Future _addEntry({bool silent = false}) async { if (products.length != 1) { - showError("Pick product first"); + if (!silent) { + showError("Pick one product"); + } return; } - var grams = await _parseDouble(gramsController.text, "Grams"); + var grams = await _parseDouble(gramsController.text); if (grams == null) { + if (!silent) { + showError("Grams must be a number"); + } return; } @@ -88,7 +92,7 @@ class _AddEntryScreen extends State { productId: products[0].id, mealId: meal!.id, ); - popMeDady(); + popMeDaddy(); } @override @@ -171,7 +175,7 @@ class _AddEntryScreen extends State { products = [product]; productNameController.text = product.name; }); - _addEntry(); + _addEntry(silent: true); }, title: ProductWidget( product: product, diff --git a/lib/screens/add_meal.dart b/lib/screens/add_meal.dart index 4e2a2ee..c2f19c3 100644 --- a/lib/screens/add_meal.dart +++ b/lib/screens/add_meal.dart @@ -30,7 +30,7 @@ class _AddMealScreen extends State { super.dispose(); } - void popMeDady() { + void popMeDaddy() { Navigator.pop( context, ); @@ -52,7 +52,7 @@ class _AddMealScreen extends State { diaryId: widget.diary.id, order: widget.diary.meals.length, ); - popMeDady(); + popMeDaddy(); } @override diff --git a/lib/screens/add_product.dart b/lib/screens/add_product.dart index b0a2c74..b6669f6 100644 --- a/lib/screens/add_product.dart +++ b/lib/screens/add_product.dart @@ -29,7 +29,7 @@ class _AddProductScreen extends State { super.dispose(); } - void popMeDady(Product product) { + void popMeDaddy(Product product) { Navigator.pop( context, product, @@ -74,7 +74,7 @@ class _AddProductScreen extends State { name: nameController.text, ); var product = Product.fromJson(productJson); - popMeDady(product); + popMeDaddy(product); } catch (e) { showError("Error adding product, make sure there is no product with the same name"); return; diff --git a/lib/screens/edit_entry.dart b/lib/screens/edit_entry.dart index f462e76..4d11b3b 100644 --- a/lib/screens/edit_entry.dart +++ b/lib/screens/edit_entry.dart @@ -30,7 +30,7 @@ class _EditEntryScreen extends State { super.dispose(); } - void popMeDady() { + void popMeDaddy() { Navigator.pop(context); } @@ -87,12 +87,12 @@ class _EditEntryScreen extends State { productId: products[0].id, mealId: widget.entry.mealId, ); - popMeDady(); + popMeDaddy(); } Future _deleteEntry() async { await widget.apiClient.deleteEntry(widget.entry.id); - popMeDady(); + popMeDaddy(); } @override diff --git a/lib/screens/login.dart b/lib/screens/login.dart index 46a5812..74ed914 100644 --- a/lib/screens/login.dart +++ b/lib/screens/login.dart @@ -44,7 +44,7 @@ class _LoginScreen extends State { ); } - void popMeDady() { + void popMeDaddy() { Navigator.pushReplacement( context, MaterialPageRoute( @@ -61,7 +61,7 @@ class _LoginScreen extends State { passwordController.text, ); showText("Logged in"); - popMeDady(); + popMeDaddy(); } on Exception catch (e) { showError(e.toString()); } @@ -88,7 +88,7 @@ class _LoginScreen extends State { try { await widget.apiClient.refresh(); showText("Welcome back!"); - popMeDady(); + popMeDaddy(); } on Exception catch (_) { showError("Session is not longer valid, please log in again"); } diff --git a/lib/screens/register.dart b/lib/screens/register.dart index f1db545..17ec7fc 100644 --- a/lib/screens/register.dart +++ b/lib/screens/register.dart @@ -56,7 +56,7 @@ class _RegisterScreen extends State { ); } - void popMeDady() { + void popMeDaddy() { Navigator.pop(context); } @@ -73,7 +73,7 @@ class _RegisterScreen extends State { passwordController.text, ); showText("Created account. You can now log in."); - popMeDady(); + popMeDaddy(); } on Exception catch (e) { showError(e.toString()); }