From 453926e6d36e42dcfc666d1b5a3d20c269748e47 Mon Sep 17 00:00:00 2001 From: broodjeaap89 Date: Tue, 14 Sep 2021 21:05:22 +0200 Subject: [PATCH] normalize ingredient ratios to add up to 1 --- lib/pages/edit_recipe_page.dart | 6 ++++++ todo.md | 1 - 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/pages/edit_recipe_page.dart b/lib/pages/edit_recipe_page.dart index d643684..662833f 100644 --- a/lib/pages/edit_recipe_page.dart +++ b/lib/pages/edit_recipe_page.dart @@ -188,6 +188,12 @@ class EditRecipePageState extends State { ), TextButton( onPressed: () async { + // Normalize ratios so they add up to 1 + final totalRatio = pizzaRecipe.ingredients.map((ingredient) => ingredient.value).reduce((a, b) => a + b); + for (final ingredient in pizzaRecipe.ingredients){ + ingredient.value = ingredient.value / totalRatio; + } + if (pizzaRecipe.isInBox){ pizzaRecipe.save(); } else { diff --git a/todo.md b/todo.md index 66b0b12..3c2433b 100644 --- a/todo.md +++ b/todo.md @@ -15,6 +15,5 @@ ## Bug - add option to start recipe step instruction after step datetime and not completed -- recalculate ingredient ratios to total=1 before saving when creating/editing recipes - when deleting recipes, it deletes 2, but not when deleting the last one - user should only be able to archive a pizza event that has taken place (dateTime>now) \ No newline at end of file