refactored the pizza event page to be about the pizza event, with a button to go to the recipe page for that event.
This commit is contained in:
parent
7f3d7202b9
commit
34d0eb8c08
2 changed files with 51 additions and 174 deletions
|
@ -14,6 +14,7 @@ import 'package:pizzaplanner/pages/PizzaEventsPage.dart';
|
||||||
|
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive/hive.dart';
|
||||||
import 'package:hive_flutter/hive_flutter.dart';
|
import 'package:hive_flutter/hive_flutter.dart';
|
||||||
|
import 'package:pizzaplanner/pages/PizzaRecipePage.dart';
|
||||||
import 'package:pizzaplanner/pages/RecipeStepInstructionPage.dart';
|
import 'package:pizzaplanner/pages/RecipeStepInstructionPage.dart';
|
||||||
import 'package:pizzaplanner/recipes/NeapolitanCold.dart';
|
import 'package:pizzaplanner/recipes/NeapolitanCold.dart';
|
||||||
import 'package:pizzaplanner/util.dart';
|
import 'package:pizzaplanner/util.dart';
|
||||||
|
@ -136,6 +137,9 @@ class RouteGenerator {
|
||||||
case "/event/view": {
|
case "/event/view": {
|
||||||
return MaterialPageRoute(builder: (context) => PizzaEventPage(settings.arguments as PizzaEvent));
|
return MaterialPageRoute(builder: (context) => PizzaEventPage(settings.arguments as PizzaEvent));
|
||||||
}
|
}
|
||||||
|
case "/event/recipe": {
|
||||||
|
return MaterialPageRoute(builder: (context) => PizzaRecipePage(settings.arguments as PizzaEvent));
|
||||||
|
}
|
||||||
case "/event/notification": {
|
case "/event/notification": {
|
||||||
if (selectedNotificationPayload != null) {
|
if (selectedNotificationPayload != null) {
|
||||||
return MaterialPageRoute(builder: (context) => PizzaEventNotificationPage(selectedNotificationPayload!));
|
return MaterialPageRoute(builder: (context) => PizzaEventNotificationPage(selectedNotificationPayload!));
|
||||||
|
|
|
@ -18,18 +18,11 @@ class PizzaEventPage extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class PizzaEventPageState extends State<PizzaEventPage> {
|
class PizzaEventPageState extends State<PizzaEventPage> {
|
||||||
late final PageController controller;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState(){
|
|
||||||
super.initState();
|
|
||||||
// Set first page to the first recipeStep that's not completed
|
|
||||||
int initialPage = this.widget.pizzaEvent.recipe.recipeSteps.indexWhere((recipeStep) => !(recipeStep.completed));
|
|
||||||
this.controller = PageController(initialPage: initialPage);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
var recipeStepCount = this.widget.pizzaEvent.recipe.recipeSteps.length;
|
||||||
|
var completedRecipeStepCount = this.widget.pizzaEvent.recipe.recipeSteps.where((recipeStep) => recipeStep.completed).length;
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text(this.widget.pizzaEvent.name),
|
title: Text(this.widget.pizzaEvent.name),
|
||||||
|
@ -37,177 +30,57 @@ class PizzaEventPageState extends State<PizzaEventPage> {
|
||||||
resizeToAvoidBottomInset: false,
|
resizeToAvoidBottomInset: false,
|
||||||
body: Container(
|
body: Container(
|
||||||
padding: EdgeInsets.all(10),
|
padding: EdgeInsets.all(10),
|
||||||
child: PageView(
|
child: Column(
|
||||||
scrollDirection: Axis.horizontal,
|
children: <Widget>[
|
||||||
controller: this.controller,
|
Expanded(
|
||||||
children: this.widget.pizzaEvent.recipe.recipeSteps.map((recipeStep) => buildRecipeStep(recipeStep)).toList()
|
flex: 10,
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: <Widget>[
|
||||||
|
Text(this.widget.pizzaEvent.name),
|
||||||
|
Text("$completedRecipeStepCount/$recipeStepCount")
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Divider(),
|
||||||
|
Expanded(
|
||||||
|
flex: 80,
|
||||||
|
child: ListView(
|
||||||
|
children: <Widget>[
|
||||||
|
MarkdownBody(data: this.widget.pizzaEvent.recipe.description),
|
||||||
|
Divider(),
|
||||||
|
this.widget.pizzaEvent.recipe.getIngredientsTable(this.widget.pizzaEvent.pizzaCount, this.widget.pizzaEvent.doughBallSize),
|
||||||
|
] + this.widget.pizzaEvent.recipe.recipeSteps.map((recipeStep) => buildRecipeStepWhenWidget(recipeStep)).toList()
|
||||||
|
)
|
||||||
|
),
|
||||||
|
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);
|
||||||
|
},
|
||||||
|
)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
],
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget buildRecipeStep(RecipeStep recipeStep) {
|
Widget buildRecipeStepWhenWidget(RecipeStep recipeStep){
|
||||||
var subSteps = recipeStep.subSteps.length == 0 ? 1 : recipeStep.subSteps.length;
|
return Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
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(
|
Text(recipeStep.name),
|
||||||
flex: 10,
|
// TODO add when todo/when completed
|
||||||
child: Row(
|
Icon(recipeStep.completed ? FontAwesome5.check : FontAwesome5.clock)
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
||||||
children: <Widget>[
|
|
||||||
Text(recipeStep.name),
|
|
||||||
Text("$completedSubSteps/$subSteps")
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Expanded(
|
|
||||||
flex: 80,
|
|
||||||
child: ListView(
|
|
||||||
children: <Widget>[
|
|
||||||
MarkdownBody(data: recipeStep.description),
|
|
||||||
Divider(),
|
|
||||||
] + recipeStep.subSteps.asMap().map<int, Widget>((index, subStep) => MapEntry(index, getSubStepWidget(subStep, index, currentSubStep))).values.toList()
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Expanded(
|
|
||||||
flex: 10,
|
|
||||||
child: SizedBox(
|
|
||||||
width: double.infinity,
|
|
||||||
child: Row(
|
|
||||||
children: <Widget>[
|
|
||||||
Expanded(
|
|
||||||
flex: 10,
|
|
||||||
child: Container(
|
|
||||||
padding: EdgeInsets.all(5),
|
|
||||||
color: Colors.blue,
|
|
||||||
child: TextButton(
|
|
||||||
child: Text("Undo", style: TextStyle(color: Colors.white)),
|
|
||||||
onPressed: () {
|
|
||||||
recipeStep.subSteps.map((subStep) => subStep.completedOn = null);
|
|
||||||
//controller.nextPage(duration: Duration(milliseconds: 100), curve: Curves.bounceIn);
|
|
||||||
},
|
|
||||||
)
|
|
||||||
)
|
|
||||||
),
|
|
||||||
Expanded(
|
|
||||||
flex: 2,
|
|
||||||
child: Container(),
|
|
||||||
),
|
|
||||||
Expanded(
|
|
||||||
flex: 10,
|
|
||||||
child: Container(
|
|
||||||
padding: EdgeInsets.all(5),
|
|
||||||
color: Colors.blue,
|
|
||||||
child: TextButton(
|
|
||||||
child: Text("Complete ->", style: TextStyle(color: Colors.white)),
|
|
||||||
onPressed: () {
|
|
||||||
recipeStep.subSteps.where((recipeSubStep) => !(recipeSubStep.completed)).completeNow();
|
|
||||||
//recipeStep.completeStepNow();
|
|
||||||
//this.widget.pizzaEvent.save();
|
|
||||||
//controller.nextPage(duration: Duration(milliseconds: 100), curve: Curves.bounceIn);
|
|
||||||
},
|
|
||||||
)
|
|
||||||
)
|
|
||||||
),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget buildRecipeStepWidgetWithSubSteps(RecipeStep recipeStep){
|
|
||||||
int recipeSubStepsCompleted = recipeStep.subSteps.where((subStep) => subStep.completed).length;
|
|
||||||
int recipeSubSteps = recipeStep.subSteps.length;
|
|
||||||
return ExpansionTile(
|
|
||||||
title: Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
||||||
children: <Widget>[
|
|
||||||
Icon(FontAwesome5.sitemap),
|
|
||||||
Text(recipeStep.name),
|
|
||||||
Text("$recipeSubStepsCompleted/$recipeSubSteps")
|
|
||||||
],
|
|
||||||
),
|
|
||||||
children: <Widget>[
|
|
||||||
Text(recipeStep.description),
|
|
||||||
]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget getSubStepWidget(RecipeSubStep recipeSubStep, int index, int current){
|
|
||||||
return ExpansionTile(
|
|
||||||
initiallyExpanded: index == current,
|
|
||||||
title: Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
||||||
children: <Widget>[
|
|
||||||
Text(recipeSubStep.name),
|
|
||||||
Icon(FontAwesome5.check, color: recipeSubStep.completed ? Colors.green : Colors.grey),
|
|
||||||
]
|
|
||||||
),
|
|
||||||
children: <Widget>[
|
|
||||||
MarkdownBody(
|
|
||||||
data: recipeSubStep.description,
|
|
||||||
onTapLink: (text, url, title) {
|
|
||||||
launch(url!);
|
|
||||||
},
|
|
||||||
)
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class SubStepDialog extends StatefulWidget {
|
|
||||||
final RecipeSubStep recipeSubStep;
|
|
||||||
|
|
||||||
SubStepDialog(this.recipeSubStep);
|
|
||||||
|
|
||||||
SubStepDialogState createState() => SubStepDialogState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class SubStepDialogState extends State<SubStepDialog> {
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Dialog(
|
|
||||||
insetPadding: EdgeInsets.all(10),
|
|
||||||
child: Container(
|
|
||||||
padding: EdgeInsets.all(10),
|
|
||||||
child: Column(
|
|
||||||
children: <Widget>[
|
|
||||||
Text(this.widget.recipeSubStep.name),
|
|
||||||
Text(this.widget.recipeSubStep.description),
|
|
||||||
Expanded(
|
|
||||||
child: Container()
|
|
||||||
),
|
|
||||||
SizedBox(
|
|
||||||
width: double.infinity,
|
|
||||||
height: 70,
|
|
||||||
child: Container(
|
|
||||||
color: this.widget.recipeSubStep.completed ? Colors.green : Colors.grey,
|
|
||||||
child: TextButton(
|
|
||||||
child: Text(this.widget.recipeSubStep.completed ? "Complete" : "Todo", style: TextStyle(color: Colors.white)),
|
|
||||||
onPressed: () {
|
|
||||||
setState(() {
|
|
||||||
this.widget.recipeSubStep.completedOn = this.widget.recipeSubStep.completed ? null : DateTime.now();
|
|
||||||
});
|
|
||||||
},
|
|
||||||
)
|
|
||||||
)
|
|
||||||
),
|
|
||||||
]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue