[rename] pushMeDaddy [addEntry] add silent mode when selecting product

This commit is contained in:
doman 2023-08-26 22:56:43 +02:00
parent b1915d5807
commit 4cc78fb657
6 changed files with 24 additions and 20 deletions

View file

@ -31,7 +31,7 @@ class _AddEntryScreen extends State<AddEntryScreen> {
super.dispose(); super.dispose();
} }
void popMeDady() { void popMeDaddy() {
Navigator.pop( Navigator.pop(
context, context,
); );
@ -63,23 +63,27 @@ class _AddEntryScreen extends State<AddEntryScreen> {
); );
} }
Future<double?> _parseDouble(String text, String name) async { Future<double?> _parseDouble(String text) async {
try { try {
return double.parse(text.replaceAll(",", ".")); return double.parse(text.replaceAll(",", "."));
} catch (e) { } catch (e) {
showError("$name must be a number");
return null; return null;
} }
} }
Future<void> _addEntry() async { Future<void> _addEntry({bool silent = false}) async {
if (products.length != 1) { if (products.length != 1) {
showError("Pick product first"); if (!silent) {
showError("Pick one product");
}
return; return;
} }
var grams = await _parseDouble(gramsController.text, "Grams"); var grams = await _parseDouble(gramsController.text);
if (grams == null) { if (grams == null) {
if (!silent) {
showError("Grams must be a number");
}
return; return;
} }
@ -88,7 +92,7 @@ class _AddEntryScreen extends State<AddEntryScreen> {
productId: products[0].id, productId: products[0].id,
mealId: meal!.id, mealId: meal!.id,
); );
popMeDady(); popMeDaddy();
} }
@override @override
@ -171,7 +175,7 @@ class _AddEntryScreen extends State<AddEntryScreen> {
products = [product]; products = [product];
productNameController.text = product.name; productNameController.text = product.name;
}); });
_addEntry(); _addEntry(silent: true);
}, },
title: ProductWidget( title: ProductWidget(
product: product, product: product,

View file

@ -30,7 +30,7 @@ class _AddMealScreen extends State<AddMealScreen> {
super.dispose(); super.dispose();
} }
void popMeDady() { void popMeDaddy() {
Navigator.pop( Navigator.pop(
context, context,
); );
@ -52,7 +52,7 @@ class _AddMealScreen extends State<AddMealScreen> {
diaryId: widget.diary.id, diaryId: widget.diary.id,
order: widget.diary.meals.length, order: widget.diary.meals.length,
); );
popMeDady(); popMeDaddy();
} }
@override @override

View file

@ -29,7 +29,7 @@ class _AddProductScreen extends State<AddProductScreen> {
super.dispose(); super.dispose();
} }
void popMeDady(Product product) { void popMeDaddy(Product product) {
Navigator.pop( Navigator.pop(
context, context,
product, product,
@ -74,7 +74,7 @@ class _AddProductScreen extends State<AddProductScreen> {
name: nameController.text, name: nameController.text,
); );
var product = Product.fromJson(productJson); var product = Product.fromJson(productJson);
popMeDady(product); popMeDaddy(product);
} catch (e) { } catch (e) {
showError("Error adding product, make sure there is no product with the same name"); showError("Error adding product, make sure there is no product with the same name");
return; return;

View file

@ -30,7 +30,7 @@ class _EditEntryScreen extends State<EditEntryScreen> {
super.dispose(); super.dispose();
} }
void popMeDady() { void popMeDaddy() {
Navigator.pop(context); Navigator.pop(context);
} }
@ -87,12 +87,12 @@ class _EditEntryScreen extends State<EditEntryScreen> {
productId: products[0].id, productId: products[0].id,
mealId: widget.entry.mealId, mealId: widget.entry.mealId,
); );
popMeDady(); popMeDaddy();
} }
Future<void> _deleteEntry() async { Future<void> _deleteEntry() async {
await widget.apiClient.deleteEntry(widget.entry.id); await widget.apiClient.deleteEntry(widget.entry.id);
popMeDady(); popMeDaddy();
} }
@override @override

View file

@ -44,7 +44,7 @@ class _LoginScreen extends State<LoginScreen> {
); );
} }
void popMeDady() { void popMeDaddy() {
Navigator.pushReplacement( Navigator.pushReplacement(
context, context,
MaterialPageRoute( MaterialPageRoute(
@ -61,7 +61,7 @@ class _LoginScreen extends State<LoginScreen> {
passwordController.text, passwordController.text,
); );
showText("Logged in"); showText("Logged in");
popMeDady(); popMeDaddy();
} on Exception catch (e) { } on Exception catch (e) {
showError(e.toString()); showError(e.toString());
} }
@ -88,7 +88,7 @@ class _LoginScreen extends State<LoginScreen> {
try { try {
await widget.apiClient.refresh(); await widget.apiClient.refresh();
showText("Welcome back!"); showText("Welcome back!");
popMeDady(); popMeDaddy();
} on Exception catch (_) { } on Exception catch (_) {
showError("Session is not longer valid, please log in again"); showError("Session is not longer valid, please log in again");
} }

View file

@ -56,7 +56,7 @@ class _RegisterScreen extends State<RegisterScreen> {
); );
} }
void popMeDady() { void popMeDaddy() {
Navigator.pop(context); Navigator.pop(context);
} }
@ -73,7 +73,7 @@ class _RegisterScreen extends State<RegisterScreen> {
passwordController.text, passwordController.text,
); );
showText("Created account. You can now log in."); showText("Created account. You can now log in.");
popMeDady(); popMeDaddy();
} on Exception catch (e) { } on Exception catch (e) {
showError(e.toString()); showError(e.toString());
} }