From f8285159cf1911dba46a6a5e20e4f0066112bcbe Mon Sep 17 00:00:00 2001 From: broodjeaap89 Date: Sun, 29 Aug 2021 15:45:15 +0200 Subject: [PATCH] completed the pizza event page (for now) --- lib/pages/PizzaEventPage.dart | 102 ++++++++++++++++++++++++---------- 1 file changed, 72 insertions(+), 30 deletions(-) diff --git a/lib/pages/PizzaEventPage.dart b/lib/pages/PizzaEventPage.dart index 33a9a2e..eefda3f 100644 --- a/lib/pages/PizzaEventPage.dart +++ b/lib/pages/PizzaEventPage.dart @@ -3,9 +3,12 @@ import 'package:flutter_local_notifications/flutter_local_notifications.dart'; import 'package:flutter_markdown/flutter_markdown.dart'; import 'package:fluttericon/font_awesome5_icons.dart'; import 'package:pizzaplanner/entities/PizzaEvent.dart'; +import 'package:pizzaplanner/entities/PizzaRecipe/Ingredient.dart'; import 'package:pizzaplanner/entities/PizzaRecipe/RecipeStep.dart'; import 'package:pizzaplanner/entities/PizzaRecipe/RecipeSubStep.dart'; import 'package:pizzaplanner/main.dart'; +import 'package:pizzaplanner/util.dart'; +import 'package:pizzaplanner/widgets/PizzaRecipeWidget.dart'; import 'package:url_launcher/url_launcher.dart'; class PizzaEventPage extends StatefulWidget { @@ -33,11 +36,20 @@ class PizzaEventPageState extends State { child: Column( children: [ Expanded( - flex: 10, + flex: 15, child: Column( children: [ Text(this.widget.pizzaEvent.name), - Text(getTimeRemainingString(this.widget.pizzaEvent.dateTime)) + Text(getTimeRemainingString(this.widget.pizzaEvent.dateTime)), + Container( + color: Colors.blue, + child: TextButton( + child: Text(this.widget.pizzaEvent.recipe.name, style: TextStyle(color: Colors.white)), + onPressed: () { + Navigator.pushNamed(context, "/event/recipe", arguments: this.widget.pizzaEvent); + }, + ) + ) ], ), ), @@ -46,45 +58,75 @@ class PizzaEventPageState extends State { flex: 80, child: ListView( children: [ - MarkdownBody( - data: this.widget.pizzaEvent.recipe.description, - onTapLink: (text, url, title) { - launch(url!); + Center( + child: Text("Ingredients") + ), + Table( + columnWidths: const { + 0: FlexColumnWidth(5), + 1: FlexColumnWidth(5), + 3: FlexColumnWidth(1), }, + children: [ + TableRow( + children: [ + TableCell(child: Text("Ingredient")), + TableCell(child: Text("Total")), + TableCell(child: Center(child: Text("0/4"))) + ] + ) + ] + this.widget.pizzaEvent.recipe.ingredients.map((ingredient) => buildIngredientWidget(ingredient)).toList(), + ), + Table( + columnWidths: const { + 0: FlexColumnWidth(5), + 1: FlexColumnWidth(5), + 2: FlexColumnWidth(1), + }, + children: [ + TableRow( + children: [ + TableCell(child: Text("Recipe Step")), + TableCell(child: Text("When")), + TableCell(child: Text("$completedRecipeStepCount/$recipeStepCount")), + ] + ) + ] + this.widget.pizzaEvent.recipe.recipeSteps.map((recipeStep) => buildRecipeStepWhenWidget(recipeStep)).toList() ), Divider(), - this.widget.pizzaEvent.recipe.getIngredientsTable(this.widget.pizzaEvent.pizzaCount, this.widget.pizzaEvent.doughBallSize), - ] + this.widget.pizzaEvent.recipe.recipeSteps.map((recipeStep) => buildRecipeStepWhenWidget(recipeStep)).toList() + ] ) ), - Expanded( - flex: 10, - child: Container( - width: double.infinity, - padding: EdgeInsets.all(10), - color: Colors.blue, - child: TextButton( - child: Text("Start", style: TextStyle(color: Colors.white)), - onPressed: () { - Navigator.pushNamed(context, "/event/recipe", arguments: this.widget.pizzaEvent); - }, - ) - ) - ), ], ) ) ); } - Widget buildRecipeStepWhenWidget(RecipeStep recipeStep){ - return Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text(recipeStep.name), - // TODO add when todo/when completed - Icon(recipeStep.completed ? FontAwesome5.check : FontAwesome5.clock) - ], + TableRow buildIngredientWidget(Ingredient ingredient){ + int totalWeight = this.widget.pizzaEvent.pizzaCount * this.widget.pizzaEvent.doughBallSize; + return TableRow( + children: [ + TableCell(child: Text(ingredient.name)), + TableCell(child: Text("${ingredient.getAbsolute(totalWeight)}")), + TableCell(child: Center(child: Checkbox( + value: ingredient.bought, + onChanged: (bool? newValue) { + setState((){ingredient.bought = newValue!;}); + this.widget.pizzaEvent.save(); + }, + ))), + ] + ); + } + + TableRow buildRecipeStepWhenWidget(RecipeStep recipeStep){ + return TableRow( + children: [ + TableCell(child: Text(recipeStep.name)), + TableCell(child: Text(getDateFormat().format(recipeStep.dateTime))), + TableCell(child: Center(child: Icon(recipeStep.completed ? FontAwesome5.check : FontAwesome5.clock))), + ] ); } } \ No newline at end of file