diff --git a/lib/main.dart b/lib/main.dart index f8b7832..df15fb4 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -14,6 +14,7 @@ import 'package:pizzaplanner/pages/PizzaEventsPage.dart'; import 'package:hive/hive.dart'; import 'package:hive_flutter/hive_flutter.dart'; +import 'package:pizzaplanner/pages/PizzaRecipePage.dart'; import 'package:pizzaplanner/pages/RecipeStepInstructionPage.dart'; import 'package:pizzaplanner/recipes/NeapolitanCold.dart'; import 'package:pizzaplanner/util.dart'; @@ -136,6 +137,9 @@ class RouteGenerator { case "/event/view": { return MaterialPageRoute(builder: (context) => PizzaEventPage(settings.arguments as PizzaEvent)); } + case "/event/recipe": { + return MaterialPageRoute(builder: (context) => PizzaRecipePage(settings.arguments as PizzaEvent)); + } case "/event/notification": { if (selectedNotificationPayload != null) { return MaterialPageRoute(builder: (context) => PizzaEventNotificationPage(selectedNotificationPayload!)); diff --git a/lib/pages/PizzaEventPage.dart b/lib/pages/PizzaEventPage.dart index 1464ec3..e89f9a0 100644 --- a/lib/pages/PizzaEventPage.dart +++ b/lib/pages/PizzaEventPage.dart @@ -18,18 +18,11 @@ class PizzaEventPage extends StatefulWidget { } class PizzaEventPageState extends State { - late final PageController controller; - - @override - void initState(){ - super.initState(); - // Set first page to the first recipeStep that's not completed - int initialPage = this.widget.pizzaEvent.recipe.recipeSteps.indexWhere((recipeStep) => !(recipeStep.completed)); - this.controller = PageController(initialPage: initialPage); - } @override Widget build(BuildContext context) { + var recipeStepCount = this.widget.pizzaEvent.recipe.recipeSteps.length; + var completedRecipeStepCount = this.widget.pizzaEvent.recipe.recipeSteps.where((recipeStep) => recipeStep.completed).length; return Scaffold( appBar: AppBar( title: Text(this.widget.pizzaEvent.name), @@ -37,177 +30,57 @@ class PizzaEventPageState extends State { resizeToAvoidBottomInset: false, body: Container( padding: EdgeInsets.all(10), - child: PageView( - scrollDirection: Axis.horizontal, - controller: this.controller, - children: this.widget.pizzaEvent.recipe.recipeSteps.map((recipeStep) => buildRecipeStep(recipeStep)).toList() + child: Column( + children: [ + Expanded( + flex: 10, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text(this.widget.pizzaEvent.name), + Text("$completedRecipeStepCount/$recipeStepCount") + ], + ), + ), + Divider(), + Expanded( + flex: 80, + child: ListView( + children: [ + MarkdownBody(data: this.widget.pizzaEvent.recipe.description), + 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 buildRecipeStep(RecipeStep recipeStep) { - 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( + + Widget buildRecipeStepWhenWidget(RecipeStep recipeStep){ + return Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Expanded( - flex: 10, - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text(recipeStep.name), - Text("$completedSubSteps/$subSteps") - ], - ), - ), - Expanded( - flex: 80, - 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, - child: SizedBox( - width: double.infinity, - child: Row( - children: [ - Expanded( - flex: 10, - child: Container( - padding: EdgeInsets.all(5), - color: Colors.blue, - child: TextButton( - child: Text("Undo", style: TextStyle(color: Colors.white)), - onPressed: () { - 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( - padding: EdgeInsets.all(5), - color: Colors.blue, - child: TextButton( - child: Text("Complete ->", style: TextStyle(color: Colors.white)), - onPressed: () { - recipeStep.subSteps.where((recipeSubStep) => !(recipeSubStep.completed)).completeNow(); - //recipeStep.completeStepNow(); - //this.widget.pizzaEvent.save(); - //controller.nextPage(duration: Duration(milliseconds: 100), curve: Curves.bounceIn); - }, - ) - ) - ), - ], - ) - ) - ) + Text(recipeStep.name), + // TODO add when todo/when completed + Icon(recipeStep.completed ? FontAwesome5.check : FontAwesome5.clock) ], ); } - - Widget buildRecipeStepWidgetWithSubSteps(RecipeStep recipeStep){ - int recipeSubStepsCompleted = recipeStep.subSteps.where((subStep) => subStep.completed).length; - int recipeSubSteps = recipeStep.subSteps.length; - return ExpansionTile( - title: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Icon(FontAwesome5.sitemap), - Text(recipeStep.name), - Text("$recipeSubStepsCompleted/$recipeSubSteps") - ], - ), - children: [ - Text(recipeStep.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!); - }, - ) - ], - ); - } -} - -class SubStepDialog extends StatefulWidget { - final RecipeSubStep recipeSubStep; - - SubStepDialog(this.recipeSubStep); - - SubStepDialogState createState() => SubStepDialogState(); -} - -class SubStepDialogState extends State { - @override - Widget build(BuildContext context) { - return Dialog( - insetPadding: EdgeInsets.all(10), - child: Container( - padding: EdgeInsets.all(10), - child: Column( - children: [ - Text(this.widget.recipeSubStep.name), - Text(this.widget.recipeSubStep.description), - Expanded( - child: Container() - ), - SizedBox( - width: double.infinity, - height: 70, - child: Container( - color: this.widget.recipeSubStep.completed ? Colors.green : Colors.grey, - child: TextButton( - child: Text(this.widget.recipeSubStep.completed ? "Complete" : "Todo", style: TextStyle(color: Colors.white)), - onPressed: () { - setState(() { - this.widget.recipeSubStep.completedOn = this.widget.recipeSubStep.completed ? null : DateTime.now(); - }); - }, - ) - ) - ), - ] - ) - ) - ); - } } \ No newline at end of file