diff --git a/assets/recipes/neapolitan.yaml b/assets/recipes/neapolitan_cold.yaml similarity index 100% rename from assets/recipes/neapolitan.yaml rename to assets/recipes/neapolitan_cold.yaml diff --git a/lib/entities/PizzaRecipe/PizzaRecipe.dart b/lib/entities/PizzaRecipe/PizzaRecipe.dart index 7636af9..0b5d651 100644 --- a/lib/entities/PizzaRecipe/PizzaRecipe.dart +++ b/lib/entities/PizzaRecipe/PizzaRecipe.dart @@ -2,6 +2,8 @@ import 'package:flutter/services.dart' show rootBundle; import 'package:pizzaplanner/entities/PizzaRecipe/Ingredient.dart'; import 'package:pizzaplanner/entities/PizzaRecipe/Ingredients.dart'; +import 'package:pizzaplanner/entities/PizzaRecipe/RecipeStep.dart'; +import 'package:pizzaplanner/entities/PizzaRecipe/RecipeSubStep.dart'; import 'package:yaml/yaml.dart'; class PizzaRecipe { @@ -9,10 +11,12 @@ class PizzaRecipe { final String description; final Ingredients ingredients; - PizzaRecipe(this.name, this.description, this.ingredients); + final List recipeSteps; + + PizzaRecipe(this.name, this.description, this.ingredients, this.recipeSteps); static Future fromYaml() async{ - String yamlString = await loadAsset("assets/recipes/neapolitan.yaml"); + String yamlString = await loadAsset("assets/recipes/neapolitan_cold.yaml"); var yaml = loadYaml(yamlString); var recipe = yaml["recipe"]; @@ -28,12 +32,38 @@ class PizzaRecipe { value: (ingredient) => Ingredient(ingredient["name"], ingredient["unit"], ingredient["value"]) ); - print(newIngredients); + YamlList steps = recipe["steps"]; + var newRecipeSteps = List.generate(steps.length, (i) { + YamlMap step = steps[i]; + String stepName = step["name"]; + String stepDescription = step["description"]; + + YamlMap waitMap = step.containsKey("wait") ? step["wait"] : YamlList(); + String waitUnit = waitMap["unit"]; + int waitMin = waitMap["min"]; + int waitMax = waitMap["max"]; + print(step); + + YamlList subSteps = step.containsKey("substeps") ? step["substeps"] : YamlList(); + var newSubSteps = List.generate(subSteps.length, (j) { + var subStep = subSteps[j]; + return RecipeSubStep(subStep["name"], subStep["description"]); + }); + return RecipeStep( + stepName, + stepDescription, + waitUnit, + waitMin, + waitMax, + newSubSteps + ); + }); return PizzaRecipe( name, description, - Ingredients(newIngredients, ingredientMethod) + Ingredients(newIngredients, ingredientMethod), + newRecipeSteps ); } } diff --git a/lib/entities/PizzaRecipe/RecipeStep.dart b/lib/entities/PizzaRecipe/RecipeStep.dart new file mode 100644 index 0000000..218cd8c --- /dev/null +++ b/lib/entities/PizzaRecipe/RecipeStep.dart @@ -0,0 +1,12 @@ +import 'package:pizzaplanner/entities/PizzaRecipe/RecipeSubStep.dart'; + +class RecipeStep { + final String name; + final String waitUnit; + final int waitMin; + final int waitMax; + final String description; + final List subSteps; + + RecipeStep(this.name, this.description, this.waitUnit, this.waitMin, this.waitMax, this.subSteps); +} \ No newline at end of file diff --git a/lib/entities/PizzaRecipe/RecipeSubStep.dart b/lib/entities/PizzaRecipe/RecipeSubStep.dart new file mode 100644 index 0000000..af3b2c1 --- /dev/null +++ b/lib/entities/PizzaRecipe/RecipeSubStep.dart @@ -0,0 +1,6 @@ +class RecipeSubStep { + final String name; + final String description; + + RecipeSubStep(this.name, this.description); +} \ No newline at end of file