completed up the pizza event recipe page

This commit is contained in:
broodjeaap89 2021-08-29 17:19:50 +02:00
parent f8285159cf
commit 5fb483abb0

View file

@ -13,76 +13,82 @@ class PizzaEventRecipePage extends StatefulWidget {
} }
class PizzaEventRecipePageState extends State<PizzaEventRecipePage> { class PizzaEventRecipePageState extends State<PizzaEventRecipePage> {
final PageController controller = PageController();
int page = 0;
PizzaEventRecipePageState(){
this.page = controller.initialPage;
}
@override @override
Widget build(BuildContext context){ Widget build(BuildContext context){
var recipeStepCount = this.widget.pizzaEvent.recipe.recipeSteps.length;
List<Text> pageIndex = [];
for (var i = 0;i < recipeStepCount;i++){
pageIndex.add(
Text(
"${i+1}",
style: TextStyle(
color: i == this.page ? Colors.blue : Colors.grey
)
)
);
if (i != recipeStepCount-1) {
pageIndex.add(
Text(" - ", style: TextStyle(color: Colors.grey))
);
}
}
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text("Pizza Event Recipe"), title: Text(this.widget.pizzaEvent.recipe.name),
), ),
resizeToAvoidBottomInset: false, resizeToAvoidBottomInset: false,
body: Container( body: Column(
padding: EdgeInsets.fromLTRB(40, 10, 40, 10), children: <Widget>[
child: Column( Expanded(
children: <Widget>[ flex: 95,
Text(this.widget.pizzaEvent.name) child: PageView(
], onPageChanged: (newPage) => setState(() {this.page = newPage;}),
) controller: controller,
children: <Widget>[
Markdown(
data: this.widget.pizzaEvent.recipe.description,
onTapLink: (text, url, title) {
launch(url!);
},
),
] + this.widget.pizzaEvent.recipe.recipeSteps.map((recipeStep) => buildRecipeStep(recipeStep)).toList()
)
),
Expanded(
flex: 5,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: pageIndex
)
)
],
) )
); );
} }
Widget buildRecipeStep(RecipeStep recipeStep) { Widget buildRecipeStep(RecipeStep recipeStep) {
var subSteps = recipeStep.subSteps.length == 0 ? 1 : recipeStep.subSteps.length; return ListView(
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(
children: <Widget>[ children: <Widget>[
Expanded( Center(
flex: 10, child: Text(recipeStep.name)
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(recipeStep.name),
Text("$completedSubSteps/$subSteps")
],
),
),
Expanded(
flex: 80,
child: ListView(
children: <Widget>[
MarkdownBody(
data: recipeStep.description,
onTapLink: (text, url, title) {
launch(url!);
},
),
]
),
),
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);
},
)
)
), ),
Container(
padding: EdgeInsets.all(16),
child: MarkdownBody(
data: recipeStep.description,
onTapLink: (text, url, title) {
launch(url!);
},
)
)
], ],
); );
} }