From 7f3d7202b99304857a444b476bf9d724fc969586 Mon Sep 17 00:00:00 2001 From: broodjeaap89 Date: Sat, 28 Aug 2021 16:23:44 +0200 Subject: [PATCH] in between commit before layout changes --- lib/pages/PizzaEventPage.dart | 106 +++++++++++++++------------------- 1 file changed, 47 insertions(+), 59 deletions(-) diff --git a/lib/pages/PizzaEventPage.dart b/lib/pages/PizzaEventPage.dart index b1d861d..1464ec3 100644 --- a/lib/pages/PizzaEventPage.dart +++ b/lib/pages/PizzaEventPage.dart @@ -6,6 +6,7 @@ import 'package:pizzaplanner/entities/PizzaEvent.dart'; import 'package:pizzaplanner/entities/PizzaRecipe/RecipeStep.dart'; import 'package:pizzaplanner/entities/PizzaRecipe/RecipeSubStep.dart'; import 'package:pizzaplanner/main.dart'; +import 'package:url_launcher/url_launcher.dart'; class PizzaEventPage extends StatefulWidget { final PizzaEvent pizzaEvent; @@ -46,34 +47,18 @@ class PizzaEventPageState extends State { } Widget buildRecipeStep(RecipeStep recipeStep) { - var r = Row( - children: [ - Expanded( - flex: 10, - child: Container( - color: Colors.blue, - child: TextButton( - child: Text("Undo", style: TextStyle(color: Colors.white)), - onPressed: () { - controller.nextPage(duration: Duration(milliseconds: 100), curve: Curves.bounceIn); - }, - ) - ) - ), - Expanded( - flex: 10, - child: Container( - color: Colors.blue, - child: TextButton( - child: Text("Complete ->", style: TextStyle(color: Colors.white)), - onPressed: () { - controller.nextPage(duration: Duration(milliseconds: 100), curve: Curves.bounceIn); - }, - ) - ) - ), - ], - ); + var subSteps = recipeStep.subSteps.length == 0 ? 1 : recipeStep.subSteps.length; + + var currentSubStep = recipeStep.subSteps.indexWhere((subStep) => subStep.completed); + if (currentSubStep == -1){ + currentSubStep = 0; + } + + var completedSubSteps = recipeStep.completed ? 1 : 0; + if (recipeStep.subSteps.length > 0){ + completedSubSteps = currentSubStep + 1; + } + return Column( children: [ Expanded( @@ -82,13 +67,18 @@ class PizzaEventPageState extends State { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text(recipeStep.name), - Text("${recipeStep.completedOn == null ? 0 : 1}/1") + Text("$completedSubSteps/$subSteps") ], ), ), Expanded( flex: 80, - child: MarkdownBody(data: recipeStep.description) + child: ListView( + children: [ + MarkdownBody(data: recipeStep.description), + Divider(), + ] + recipeStep.subSteps.asMap().map((index, subStep) => MapEntry(index, getSubStepWidget(subStep, index, currentSubStep))).values.toList() + ), ), Expanded( flex: 10, @@ -104,11 +94,16 @@ class PizzaEventPageState extends State { child: TextButton( child: Text("Undo", style: TextStyle(color: Colors.white)), onPressed: () { - controller.nextPage(duration: Duration(milliseconds: 100), curve: Curves.bounceIn); + recipeStep.subSteps.map((subStep) => subStep.completedOn = null); + //controller.nextPage(duration: Duration(milliseconds: 100), curve: Curves.bounceIn); }, ) ) ), + Expanded( + flex: 2, + child: Container(), + ), Expanded( flex: 10, child: Container( @@ -117,7 +112,10 @@ class PizzaEventPageState extends State { child: TextButton( child: Text("Complete ->", style: TextStyle(color: Colors.white)), onPressed: () { - controller.nextPage(duration: Duration(milliseconds: 100), curve: Curves.bounceIn); + recipeStep.subSteps.where((recipeSubStep) => !(recipeSubStep.completed)).completeNow(); + //recipeStep.completeStepNow(); + //this.widget.pizzaEvent.save(); + //controller.nextPage(duration: Duration(milliseconds: 100), curve: Curves.bounceIn); }, ) ) @@ -144,38 +142,28 @@ class PizzaEventPageState extends State { ), children: [ Text(recipeStep.description), - Column( - children: recipeStep.subSteps.map( - (subStep) => getSubStepWidget(subStep) - ).expand((subStep) => [Divider(), subStep]).toList() - ) ] ); } - Widget getSubStepWidget(RecipeSubStep recipeSubStep){ - return InkWell( - onLongPress: () async {}, - onTap: () async { - await showDialog( - context: context, - builder: (context) { - return SubStepDialog(recipeSubStep); - } - ); - setState(() {}); - }, - child: Container( - color: recipeSubStep.completed ? Colors.green : Colors.grey, - child: Column( - children: [ - Center( - child: Text(recipeSubStep.name), - ), - Text(recipeSubStep.description) - ], - ), + Widget getSubStepWidget(RecipeSubStep recipeSubStep, int index, int current){ + return ExpansionTile( + initiallyExpanded: index == current, + title: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text(recipeSubStep.name), + Icon(FontAwesome5.check, color: recipeSubStep.completed ? Colors.green : Colors.grey), + ] ), + children: [ + MarkdownBody( + data: recipeSubStep.description, + onTapLink: (text, url, title) { + launch(url!); + }, + ) + ], ); } }