From 44b32a641672aba9adad6cd10d37dce11d7e10af Mon Sep 17 00:00:00 2001 From: broodjeaap89 Date: Sat, 10 Jul 2021 14:44:13 +0200 Subject: [PATCH] started work on first parsing of a yaml pizza recipe --- assets/recipes/neapolitan.yaml | 65 +++++++++++++++++++++++ lib/entities/PizzaRecipe/Ingredient.dart | 7 +++ lib/entities/PizzaRecipe/Ingredients.dart | 8 +++ lib/entities/PizzaRecipe/PizzaRecipe.dart | 43 +++++++++++++++ pubspec.yaml | 5 +- 5 files changed, 126 insertions(+), 2 deletions(-) create mode 100644 assets/recipes/neapolitan.yaml create mode 100644 lib/entities/PizzaRecipe/Ingredient.dart create mode 100644 lib/entities/PizzaRecipe/Ingredients.dart create mode 100644 lib/entities/PizzaRecipe/PizzaRecipe.dart diff --git a/assets/recipes/neapolitan.yaml b/assets/recipes/neapolitan.yaml new file mode 100644 index 0000000..364ed20 --- /dev/null +++ b/assets/recipes/neapolitan.yaml @@ -0,0 +1,65 @@ +recipe: + name: "Neapolitan Cold Rise" + 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 + steps: + - name: Make the dough + wait: + unit: days + min: 1 + max: 5 + description: > + Combine all the ingredients to make the dough, we start with just the water and salt and add the yeast after adding some of the flour to not kill the yeast. + substeps: + - name: Salt+Water + description: > + Combine the salt and the water in a bowl, stir until the salt dissolves. + - name: +20% flour + description: > + Add ~20% of the flour to the water/salt mixture and mix everything together. + - name: Yeast + description: > + Add the yeast to the mixture. + - name: Flour + description: > + Add the rest of the flour to the mixture, knead the dough for 15-20 minutes. + - name: Fridge + description: > + Place the dough in a sealed/covered container in the fridge. + - name: Warm rise + wait: + unit: hours + min: 3 + max: 6 + description: > + Take the dough out of the fridge and let it come to room temperature for a final rise before baking + substeps: + - name: Split + description: > + Split the dough into smaller balls and place them into a covered/sealed container(s) + - name: Preheat Oven + wait: + unit: minutes + min: 30 + max: 120 + description: > + Preheat the oven in advance to ensure it's as hot as it can be + A high (250 to 300 degrees celsius) is recommended) + - name: Pizza Time! + description: > + Time to make pizza! \ No newline at end of file diff --git a/lib/entities/PizzaRecipe/Ingredient.dart b/lib/entities/PizzaRecipe/Ingredient.dart new file mode 100644 index 0000000..63fd3b6 --- /dev/null +++ b/lib/entities/PizzaRecipe/Ingredient.dart @@ -0,0 +1,7 @@ +class Ingredient { + final String name; + final String unit; + final double value; + + Ingredient(this.name, this.unit, this.value); +} \ No newline at end of file diff --git a/lib/entities/PizzaRecipe/Ingredients.dart b/lib/entities/PizzaRecipe/Ingredients.dart new file mode 100644 index 0000000..040d87d --- /dev/null +++ b/lib/entities/PizzaRecipe/Ingredients.dart @@ -0,0 +1,8 @@ +import 'package:pizzaplanner/entities/PizzaRecipe/Ingredient.dart'; + +class Ingredients { + final Map ingredients; + final String method; + + Ingredients(this.ingredients, this.method); +} \ No newline at end of file diff --git a/lib/entities/PizzaRecipe/PizzaRecipe.dart b/lib/entities/PizzaRecipe/PizzaRecipe.dart new file mode 100644 index 0000000..7636af9 --- /dev/null +++ b/lib/entities/PizzaRecipe/PizzaRecipe.dart @@ -0,0 +1,43 @@ +import 'package:flutter/services.dart' show rootBundle; +import 'package:pizzaplanner/entities/PizzaRecipe/Ingredient.dart'; + +import 'package:pizzaplanner/entities/PizzaRecipe/Ingredients.dart'; +import 'package:yaml/yaml.dart'; + +class PizzaRecipe { + final String name; + final String description; + final Ingredients ingredients; + + PizzaRecipe(this.name, this.description, this.ingredients); + + static Future fromYaml() async{ + String yamlString = await loadAsset("assets/recipes/neapolitan.yaml"); + var yaml = loadYaml(yamlString); + var recipe = yaml["recipe"]; + + String name = recipe["name"]; + String description = recipe["description"]; + + YamlMap ingredientsBlock = recipe["ingredients"]; + String ingredientMethod = ingredientsBlock["method"]; + YamlList ingredients = ingredientsBlock["items"]; + + var newIngredients = Map.fromIterable(ingredients, + key: (ingredient) => ingredient["name"], + value: (ingredient) => Ingredient(ingredient["name"], ingredient["unit"], ingredient["value"]) + ); + + print(newIngredients); + + return PizzaRecipe( + name, + description, + Ingredients(newIngredients, ingredientMethod) + ); + } +} + +Future loadAsset(String path) async { + return await rootBundle.loadString(path); +} \ No newline at end of file diff --git a/pubspec.yaml b/pubspec.yaml index 05e6c09..f9c3a30 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -30,6 +30,7 @@ dependencies: cupertino_icons: ^1.0.3 fluttericon: ^2.0.0 flutter_datetime_picker: ^1.5.1 + yaml: ^3.1.0 dev_dependencies: flutter_test: @@ -47,8 +48,8 @@ flutter: uses-material-design: true # To add assets to your application, add an assets section, like this: - # assets: - # - images/a_dot_burr.jpeg + assets: + - assets/recipes/ # - images/a_dot_ham.jpeg # An image asset can refer to one or more resolution-specific "variants", see