normalize ingredient ratios to add up to 1

This commit is contained in:
broodjeaap89 2021-09-14 21:05:22 +02:00
parent 231b83ba17
commit 453926e6d3
2 changed files with 6 additions and 1 deletions

View file

@ -188,6 +188,12 @@ class EditRecipePageState extends State<EditRecipePage> {
), ),
TextButton( TextButton(
onPressed: () async { onPressed: () async {
// Normalize ratios so they add up to 1
final totalRatio = pizzaRecipe.ingredients.map<double>((ingredient) => ingredient.value).reduce((a, b) => a + b);
for (final ingredient in pizzaRecipe.ingredients){
ingredient.value = ingredient.value / totalRatio;
}
if (pizzaRecipe.isInBox){ if (pizzaRecipe.isInBox){
pizzaRecipe.save(); pizzaRecipe.save();
} else { } else {

View file

@ -15,6 +15,5 @@
## Bug ## Bug
- add option to start recipe step instruction after step datetime and not completed - 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 - 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) - user should only be able to archive a pizza event that has taken place (dateTime>now)