added optional images to pizza recipes, that are displayed in the pizza recipe widget

This commit is contained in:
broodjeaap89 2021-09-25 16:18:30 +02:00
parent 2504c1632b
commit bff604b09d
3 changed files with 22 additions and 12 deletions

View file

@ -1,5 +1,6 @@
recipe: recipe:
name: "Neapolitan Cold Rise" name: "Neapolitan Cold Rise"
image: https://mypizzacorner.com/wp-content/uploads/2020/12/neapolitan-pizza-authentic.jpg?ezimgfmt=ng:webp/ngcb45
description: > description: >
A Neapolitan Style pizza with a multi day cold rise, giving a light and fluffy dough. A Neapolitan Style pizza with a multi day cold rise, giving a light and fluffy dough.

View file

@ -30,8 +30,13 @@ class PizzaRecipe extends HiveObject {
// cutting off the last item // cutting off the last item
@HiveField(4) @HiveField(4)
bool deleted = false; 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(){ String getShortDescriptionString(){
if (description.length < 150) { // TODO 150? if (description.length < 150) { // TODO 150?
@ -89,6 +94,7 @@ class PizzaRecipe extends HiveObject {
final YamlMap recipe = yaml["recipe"] as YamlMap; final YamlMap recipe = yaml["recipe"] as YamlMap;
final String name = recipe["name"] as String; 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 String description = recipe["description"] as String;
final YamlList ingredients = recipe["ingredients"] as YamlList; final YamlList ingredients = recipe["ingredients"] as YamlList;
@ -143,7 +149,8 @@ class PizzaRecipe extends HiveObject {
name, name,
description, description,
newIngredients, newIngredients,
newRecipeSteps newRecipeSteps,
image: image
); );
} }
@ -153,6 +160,11 @@ class PizzaRecipe extends HiveObject {
// Name // Name
yaml.writeln(indent(1, 'name: "$name"')); yaml.writeln(indent(1, 'name: "$name"'));
// image url
if (imgUrl != null){
yaml.writeln(indent(1, 'image: "$imgUrl"'));
}
// Description // Description
yaml.writeln(indent(1, 'description: >')); yaml.writeln(indent(1, 'description: >'));
for (final line in description.split("\n")){ for (final line in description.split("\n")){

View file

@ -1,4 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:fluttericon/font_awesome5_icons.dart';
import 'package:pizzaplanner/entities/PizzaRecipe/pizza_recipe.dart'; import 'package:pizzaplanner/entities/PizzaRecipe/pizza_recipe.dart';
class PizzaRecipeWidget extends StatelessWidget { class PizzaRecipeWidget extends StatelessWidget {
@ -9,26 +10,22 @@ class PizzaRecipeWidget extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return Container(
height: 120, //height: 120,
color: Colors.blueAccent, //color: Colors.blueAccent,
child: Container( child: Container(
padding: const EdgeInsets.all(8),
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[ children: <Widget>[
if (pizzaRecipe.imgUrl != null)
Image.network(pizzaRecipe.imgUrl!)
else
const Icon(FontAwesome5.pizza_slice, size: 100,),
Row( Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[ children: <Widget>[
Text(pizzaRecipe.name), Text(pizzaRecipe.name),
] ]
), ),
Text(pizzaRecipe.getShortDescriptionString()),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text("${pizzaRecipe.getMinDuration().inHours.round()} to ${pizzaRecipe.getMaxDuration().inHours.round()} hours")
]
)
] ]
) )
) )