From bff604b09daba4049a6b894a1e020e76adab458f Mon Sep 17 00:00:00 2001 From: broodjeaap89 Date: Sat, 25 Sep 2021 16:18:30 +0200 Subject: [PATCH] added optional images to pizza recipes, that are displayed in the pizza recipe widget --- assets/recipes/neapolitan_cold.yaml | 1 + lib/entities/PizzaRecipe/pizza_recipe.dart | 16 ++++++++++++++-- lib/widgets/pizza_recipe_widget.dart | 17 +++++++---------- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/assets/recipes/neapolitan_cold.yaml b/assets/recipes/neapolitan_cold.yaml index eac481b..52b4d74 100644 --- a/assets/recipes/neapolitan_cold.yaml +++ b/assets/recipes/neapolitan_cold.yaml @@ -1,5 +1,6 @@ recipe: name: "Neapolitan Cold Rise" + image: https://mypizzacorner.com/wp-content/uploads/2020/12/neapolitan-pizza-authentic.jpg?ezimgfmt=ng:webp/ngcb45 description: > A Neapolitan Style pizza with a multi day cold rise, giving a light and fluffy dough. diff --git a/lib/entities/PizzaRecipe/pizza_recipe.dart b/lib/entities/PizzaRecipe/pizza_recipe.dart index ff1bd82..b425370 100644 --- a/lib/entities/PizzaRecipe/pizza_recipe.dart +++ b/lib/entities/PizzaRecipe/pizza_recipe.dart @@ -30,8 +30,13 @@ class PizzaRecipe extends HiveObject { // cutting off the last item @HiveField(4) bool deleted = false; + + @HiveField(5) + String? imgUrl; - PizzaRecipe(this.name, this.description, this.ingredients, this.recipeSteps); + PizzaRecipe(this.name, this.description, this.ingredients, this.recipeSteps, {String? image}){ + imgUrl = image; + } String getShortDescriptionString(){ if (description.length < 150) { // TODO 150? @@ -89,6 +94,7 @@ class PizzaRecipe extends HiveObject { final YamlMap recipe = yaml["recipe"] as YamlMap; final String name = recipe["name"] as String; + final String? image = recipe.containsKey("image") ? recipe["image"] as String : null; final String description = recipe["description"] as String; final YamlList ingredients = recipe["ingredients"] as YamlList; @@ -143,7 +149,8 @@ class PizzaRecipe extends HiveObject { name, description, newIngredients, - newRecipeSteps + newRecipeSteps, + image: image ); } @@ -153,6 +160,11 @@ class PizzaRecipe extends HiveObject { // Name yaml.writeln(indent(1, 'name: "$name"')); + // image url + if (imgUrl != null){ + yaml.writeln(indent(1, 'image: "$imgUrl"')); + } + // Description yaml.writeln(indent(1, 'description: >')); for (final line in description.split("\n")){ diff --git a/lib/widgets/pizza_recipe_widget.dart b/lib/widgets/pizza_recipe_widget.dart index 6e0b35c..ea4a976 100644 --- a/lib/widgets/pizza_recipe_widget.dart +++ b/lib/widgets/pizza_recipe_widget.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:fluttericon/font_awesome5_icons.dart'; import 'package:pizzaplanner/entities/PizzaRecipe/pizza_recipe.dart'; class PizzaRecipeWidget extends StatelessWidget { @@ -9,26 +10,22 @@ class PizzaRecipeWidget extends StatelessWidget { @override Widget build(BuildContext context) { return Container( - height: 120, - color: Colors.blueAccent, + //height: 120, + //color: Colors.blueAccent, child: Container( - padding: const EdgeInsets.all(8), child: Column( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ + if (pizzaRecipe.imgUrl != null) + Image.network(pizzaRecipe.imgUrl!) + else + const Icon(FontAwesome5.pizza_slice, size: 100,), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Text(pizzaRecipe.name), ] ), - Text(pizzaRecipe.getShortDescriptionString()), - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text("${pizzaRecipe.getMinDuration().inHours.round()} to ${pizzaRecipe.getMaxDuration().inHours.round()} hours") - ] - ) ] ) )