finished work on the recipe step instruction page
This commit is contained in:
parent
5fb483abb0
commit
81b1bf6a82
1 changed files with 104 additions and 23 deletions
|
@ -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,37 +28,117 @@ 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(
|
||||||
children: <Widget>[
|
controller: this.controller,
|
||||||
Text(this.widget.recipeStep.name),
|
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>[
|
}
|
||||||
MarkdownBody(
|
}),
|
||||||
selectable: true,
|
children: <Widget>[
|
||||||
data: this.widget.recipeStep.description,
|
Markdown(
|
||||||
onTapLink: (text, url, title) {
|
data: this.widget.recipeStep.description,
|
||||||
launch(url!);
|
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);
|
||||||
|
},
|
||||||
|
)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
]
|
||||||
|
),
|
||||||
|
)
|
||||||
|
]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Reference in a new issue