[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();
}
void popMeDady() {
void popMeDaddy() {
Navigator.pop(
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 {
return double.parse(text.replaceAll(",", "."));
} catch (e) {
showError("$name must be a number");
return null;
}
}
Future<void> _addEntry() async {
Future<void> _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<AddEntryScreen> {
productId: products[0].id,
mealId: meal!.id,
);
popMeDady();
popMeDaddy();
}
@override
@ -171,7 +175,7 @@ class _AddEntryScreen extends State<AddEntryScreen> {
products = [product];
productNameController.text = product.name;
});
_addEntry();
_addEntry(silent: true);
},
title: ProductWidget(
product: product,

View file

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

View file

@ -29,7 +29,7 @@ class _AddProductScreen extends State<AddProductScreen> {
super.dispose();
}
void popMeDady(Product product) {
void popMeDaddy(Product product) {
Navigator.pop(
context,
product,
@ -74,7 +74,7 @@ class _AddProductScreen extends State<AddProductScreen> {
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;

View file

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

View file

@ -44,7 +44,7 @@ class _LoginScreen extends State<LoginScreen> {
);
}
void popMeDady() {
void popMeDaddy() {
Navigator.pushReplacement(
context,
MaterialPageRoute(
@ -61,7 +61,7 @@ class _LoginScreen extends State<LoginScreen> {
passwordController.text,
);
showText("Logged in");
popMeDady();
popMeDaddy();
} on Exception catch (e) {
showError(e.toString());
}
@ -88,7 +88,7 @@ class _LoginScreen extends State<LoginScreen> {
try {
await widget.apiClient.refresh();
showText("Welcome back!");
popMeDady();
popMeDaddy();
} on Exception catch (_) {
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);
}
@ -73,7 +73,7 @@ class _RegisterScreen extends State<RegisterScreen> {
passwordController.text,
);
showText("Created account. You can now log in.");
popMeDady();
popMeDaddy();
} on Exception catch (e) {
showError(e.toString());
}