finished work on the recipe step instruction page

This commit is contained in:
broodjeaap89 2021-08-29 20:52:38 +02:00
parent 5fb483abb0
commit 81b1bf6a82

View file

@ -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<RecipeStepInstructionPage> {
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: <Widget>[
ExpansionTile(
title: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(this.widget.recipeStep.name),
],
),
children: <Widget>[
MarkdownBody(
selectable: true,
data: this.widget.recipeStep.description,
onTapLink: (text, url, title) {
launch(url!);
},
padding: EdgeInsets.all(16),
child: Column(
children: <Widget>[
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: <Widget>[
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: <Widget>[
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);
},
)
)
),
]
),
)
]
)
)
);