diff --git a/lib/pages/RecipeStepInstructionPage.dart b/lib/pages/RecipeStepInstructionPage.dart index f8a5e2f..3d88019 100644 --- a/lib/pages/RecipeStepInstructionPage.dart +++ b/lib/pages/RecipeStepInstructionPage.dart @@ -3,6 +3,7 @@ import 'package:pizzaplanner/entities/PizzaEvent.dart'; import 'package:pizzaplanner/entities/PizzaRecipe/RecipeStep.dart'; import 'package:flutter_markdown/flutter_markdown.dart'; +import 'package:pizzaplanner/entities/PizzaRecipe/RecipeSubStep.dart'; import 'package:url_launcher/url_launcher.dart'; class RecipeStepInstructionPageArguments { @@ -27,37 +28,117 @@ class RecipeStepInstructionPage extends StatefulWidget { } class RecipeStepInstructionState extends State { - + final PageController controller = PageController(); + int page = 0; + RecipeSubStep? currentSubStep; + + @override + void initState() { + super.initState(); + + if (this.widget.recipeStep.subSteps.isNotEmpty) { + this.currentSubStep = this.widget.recipeStep.subSteps.first; + } + } + @override Widget build(BuildContext context) { + var nextButtonText = "Start"; + if (this.page == this.widget.recipeStep.subSteps.length){ // -1 because of description page + nextButtonText = "Finished"; + } else if (this.page > 0){ + nextButtonText = "Next step"; + } return Scaffold( appBar: AppBar( - title: Text("From notification"), + title: Text(this.widget.recipeStep.name), ), resizeToAvoidBottomInset: false, body: Container( - padding: EdgeInsets.fromLTRB(40, 10, 40, 10), - child: ListView( - children: [ - ExpansionTile( - title: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text(this.widget.recipeStep.name), - - ], - ), - children: [ - MarkdownBody( - selectable: true, - data: this.widget.recipeStep.description, - onTapLink: (text, url, title) { - launch(url!); - }, + padding: EdgeInsets.all(16), + child: Column( + children: [ + Expanded( + flex: 90, + child: PageView( + controller: this.controller, + onPageChanged: (newPage) => setState(() { + this.page = newPage; + if (this.widget.recipeStep.subSteps.isNotEmpty && this.page != 0) { + this.currentSubStep = this.widget.recipeStep.subSteps.elementAt(newPage-1); + } + }), + children: [ + Markdown( + data: this.widget.recipeStep.description, + onTapLink: (text, url, title) { + launch(url!); + }, + ) + ] + this.widget.recipeStep.subSteps.map((subStep) { + return Markdown( + data: subStep.description, + onTapLink: (text, url, title) { + launch(url!); + }, + ); + }).toList() ) - ], - ) - ] + ), + Expanded( + flex: 10, + child: Row( + children: [ + Expanded( + flex: 15, + child: Container( + width: double.infinity, + color: Colors.blue, + child: TextButton( + child: Text("Back", style: TextStyle(color: Colors.white)), + onPressed: () { + if (page == 0){ + return; + } + if (this.currentSubStep != null){ + this.currentSubStep?.completedOn = null; + this.widget.pizzaEvent.save(); + } + this.controller.previousPage(duration: const Duration(milliseconds: 100), curve: Curves.ease); + }, + ) + ) + ), + Expanded( + flex: 5, + child: Container() + ), + Expanded( + flex: 35, + child: Container( + width: double.infinity, + color: Colors.blue, + child: TextButton( + child: Text(nextButtonText, style: TextStyle(color: Colors.white)), + onPressed: () { + if (this.page == this.widget.recipeStep.subSteps.length){ + this.widget.recipeStep.completeStepNow(); + this.widget.pizzaEvent.save(); + Navigator.pop(context); + return; + } else if (this.currentSubStep != null){ + this.currentSubStep?.completeNow(); + this.widget.pizzaEvent.save(); + } + this.controller.nextPage(duration: const Duration(milliseconds: 100), curve: Curves.ease); + }, + ) + ) + ), + ] + ), + ) + ] ) ) );