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:pizzaplanner/entities/PizzaRecipe/RecipeStep.dart';
import 'package:flutter_markdown/flutter_markdown.dart'; import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:pizzaplanner/entities/PizzaRecipe/RecipeSubStep.dart';
import 'package:url_launcher/url_launcher.dart'; import 'package:url_launcher/url_launcher.dart';
class RecipeStepInstructionPageArguments { class RecipeStepInstructionPageArguments {
@ -27,35 +28,115 @@ class RecipeStepInstructionPage extends StatefulWidget {
} }
class RecipeStepInstructionState extends State<RecipeStepInstructionPage> { 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 @override
Widget build(BuildContext context) { 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( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text("From notification"), title: Text(this.widget.recipeStep.name),
), ),
resizeToAvoidBottomInset: false, resizeToAvoidBottomInset: false,
body: Container( body: Container(
padding: EdgeInsets.fromLTRB(40, 10, 40, 10), padding: EdgeInsets.all(16),
child: ListView( child: Column(
children: <Widget>[ children: <Widget>[
ExpansionTile( Expanded(
title: Row( flex: 90,
mainAxisAlignment: MainAxisAlignment.spaceBetween, 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>[ children: <Widget>[
Text(this.widget.recipeStep.name), Markdown(
],
),
children: <Widget>[
MarkdownBody(
selectable: true,
data: this.widget.recipeStep.description, data: this.widget.recipeStep.description,
onTapLink: (text, url, title) { onTapLink: (text, url, title) {
launch(url!); 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);
},
)
)
),
]
),
) )
] ]
) )