From bdd09a9a3a6af16454b06ad2aded1931a773c1dc Mon Sep 17 00:00:00 2001 From: broodjeaap89 Date: Tue, 13 Jul 2021 20:50:44 +0200 Subject: [PATCH] removed 'Ingredient' entity, and removed 'method' from yaml shema --- assets/recipes/many_step_pizza.yaml | 26 +++++++-------- assets/recipes/neapolitan_cold.yaml | 26 +++++++-------- assets/recipes/neapolitan_quick.yaml | 26 +++++++-------- assets/recipes/new_york.yaml | 26 +++++++-------- lib/entities/PizzaRecipe/Ingredients.dart | 33 ------------------- lib/entities/PizzaRecipe/PizzaRecipe.dart | 39 ++++++++++++++++------- 6 files changed, 75 insertions(+), 101 deletions(-) delete mode 100644 lib/entities/PizzaRecipe/Ingredients.dart diff --git a/assets/recipes/many_step_pizza.yaml b/assets/recipes/many_step_pizza.yaml index d97d44f..0fa6246 100644 --- a/assets/recipes/many_step_pizza.yaml +++ b/assets/recipes/many_step_pizza.yaml @@ -3,20 +3,18 @@ recipe: description: > A Neapolitan Style pizza with a multi day cold rise ingredients: - method: ratio - items: - - name: flour - unit: g - value: 0.595 - - name: water - unit: ml - value: 0.386 - - name: salt - unit: g - value: 0.0178 - - name: yeast - unit: g - value: 0.0012 + - name: flour + unit: g + value: 0.595 + - name: water + unit: ml + value: 0.386 + - name: salt + unit: g + value: 0.0178 + - name: yeast + unit: g + value: 0.0012 steps: - name: Make the dough wait: diff --git a/assets/recipes/neapolitan_cold.yaml b/assets/recipes/neapolitan_cold.yaml index da98579..2f9e8a0 100644 --- a/assets/recipes/neapolitan_cold.yaml +++ b/assets/recipes/neapolitan_cold.yaml @@ -3,20 +3,18 @@ recipe: description: > A Neapolitan Style pizza with a multi day cold rise ingredients: - method: ratio - items: - - name: flour - unit: g - value: 0.595 - - name: water - unit: ml - value: 0.386 - - name: salt - unit: g - value: 0.0178 - - name: yeast - unit: g - value: 0.0012 + - name: flour + unit: g + value: 0.595 + - name: water + unit: ml + value: 0.386 + - name: salt + unit: g + value: 0.0178 + - name: yeast + unit: g + value: 0.0012 steps: - name: Make the dough wait: diff --git a/assets/recipes/neapolitan_quick.yaml b/assets/recipes/neapolitan_quick.yaml index 819e9ee..b1a08dd 100644 --- a/assets/recipes/neapolitan_quick.yaml +++ b/assets/recipes/neapolitan_quick.yaml @@ -3,20 +3,18 @@ recipe: description: > A Neapolitan Style pizza prepared in a day ingredients: - method: ratio - items: - - name: flour - unit: g - value: 0.595 - - name: water - unit: ml - value: 0.386 - - name: salt - unit: g - value: 0.0178 - - name: yeast - unit: g - value: 0.0012 + - name: flour + unit: g + value: 0.595 + - name: water + unit: ml + value: 0.386 + - name: salt + unit: g + value: 0.0178 + - name: yeast + unit: g + value: 0.0012 steps: - name: Make the dough wait: diff --git a/assets/recipes/new_york.yaml b/assets/recipes/new_york.yaml index 0929d72..868248d 100644 --- a/assets/recipes/new_york.yaml +++ b/assets/recipes/new_york.yaml @@ -3,20 +3,18 @@ recipe: description: > A Neapolitan Style pizza prepared in a day ingredients: - method: ratio - items: - - name: flour - unit: g - value: 0.545 - - name: water - unit: ml - value: 0.436 - - name: salt - unit: g - value: 0.0178 - - name: yeast - unit: g - value: 0.0012 + - name: flour + unit: g + value: 0.545 + - name: water + unit: ml + value: 0.436 + - name: salt + unit: g + value: 0.0178 + - name: yeast + unit: g + value: 0.0012 steps: - name: Make the dough wait: diff --git a/lib/entities/PizzaRecipe/Ingredients.dart b/lib/entities/PizzaRecipe/Ingredients.dart deleted file mode 100644 index a00d7e8..0000000 --- a/lib/entities/PizzaRecipe/Ingredients.dart +++ /dev/null @@ -1,33 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:pizzaplanner/entities/PizzaRecipe/Ingredient.dart'; - -class Ingredients { - final Map ingredients; - final String method; - - Ingredients(this.ingredients, this.method); - - Table getIngredientsTable(int pizzaCount, int doughBallSize) { - return Table( - border: TableBorder.all(), - columnWidths: const { - 0: FlexColumnWidth(2), - 1: FlexColumnWidth(1), - 2: FlexColumnWidth(2), - }, - children: [ - TableRow( - children: [ - TableCell(child: Center(child: Text("Ingredient"))), - TableCell(child: Center(child: Text("Per Ball"))), - TableCell(child: Center(child: Text("Total"))), - ] - ) - - ] + - ingredients.values.map((ingredient) => - ingredient.getIngredientTableRow(pizzaCount, doughBallSize)) - .toList() - ); - } -} \ No newline at end of file diff --git a/lib/entities/PizzaRecipe/PizzaRecipe.dart b/lib/entities/PizzaRecipe/PizzaRecipe.dart index 4029170..3b22d9d 100644 --- a/lib/entities/PizzaRecipe/PizzaRecipe.dart +++ b/lib/entities/PizzaRecipe/PizzaRecipe.dart @@ -11,14 +11,34 @@ import 'package:yaml/yaml.dart'; class PizzaRecipe { final String name; final String description; - final Ingredients ingredients; + final List ingredients; final List recipeSteps; PizzaRecipe(this.name, this.description, this.ingredients, this.recipeSteps); - Widget getIngredientsTable(int pizzaCount, int doughBallSize){ - return ingredients.getIngredientsTable(pizzaCount, doughBallSize); + Table getIngredientsTable(int pizzaCount, int doughBallSize) { + return Table( + border: TableBorder.all(), + columnWidths: const { + 0: FlexColumnWidth(2), + 1: FlexColumnWidth(1), + 2: FlexColumnWidth(2), + }, + children: [ + TableRow( + children: [ + TableCell(child: Center(child: Text("Ingredient"))), + TableCell(child: Center(child: Text("Per Ball"))), + TableCell(child: Center(child: Text("Total"))), + ] + ) + + ] + + ingredients.map((ingredient) => + ingredient.getIngredientTableRow(pizzaCount, doughBallSize)) + .toList() + ); } static Future fromYaml(yamlPath) async{ @@ -29,14 +49,9 @@ class PizzaRecipe { String name = recipe["name"]; String description = recipe["description"]; - YamlMap ingredientsBlock = recipe["ingredients"]; - String ingredientMethod = ingredientsBlock["method"]; - YamlList ingredients = ingredientsBlock["items"]; + YamlList ingredients = recipe["ingredients"];; - var newIngredients = Map.fromIterable(ingredients, - key: (ingredient) => ingredient["name"], - value: (ingredient) => Ingredient(ingredient["name"], ingredient["unit"], ingredient["value"]) - ); + List newIngredients = ingredients.map((ingredient) => Ingredient(ingredient["name"], ingredient["unit"], ingredient["value"])).toList(); YamlList steps = recipe["steps"]; var newRecipeSteps = List.generate(steps.length, (i) { @@ -77,7 +92,7 @@ class PizzaRecipe { return PizzaRecipe( name, description, - Ingredients(newIngredients, ingredientMethod), + newIngredients, newRecipeSteps ); } @@ -91,7 +106,7 @@ class PizzaRecipe { } String toString() { - return "PizzaRecipe(${this.name}, ${this.ingredients.ingredients.length}, ${this.recipeSteps.length})"; + return "PizzaRecipe(${this.name}, ${this.ingredients.length}, ${this.recipeSteps.length})"; } Table getStepTimeTable(DateTime startTime) {