added a confirmation dialog when adding a PizzaEvent, that shows the ingredients and when each step/task will take place

This commit is contained in:
broodjeaap89 2021-07-11 17:59:14 +02:00
parent b2bd37075e
commit d7dd3b5ca5
4 changed files with 193 additions and 37 deletions

View file

@ -12,15 +12,14 @@ class Ingredients {
border: TableBorder.all(), border: TableBorder.all(),
columnWidths: const <int, TableColumnWidth>{ columnWidths: const <int, TableColumnWidth>{
0: FlexColumnWidth(2), 0: FlexColumnWidth(2),
1: FlexColumnWidth(2), 1: FlexColumnWidth(1),
2: FlexColumnWidth(2), 2: FlexColumnWidth(2),
}, },
children: children: <TableRow>[
<TableRow>[
TableRow( TableRow(
children: <TableCell>[ children: <TableCell>[
TableCell(child: Center(child: Text("Ingredient"))), TableCell(child: Center(child: Text("Ingredient"))),
TableCell(child: Center(child: Text("Single Ball"))), TableCell(child: Center(child: Text("Per Ball"))),
TableCell(child: Center(child: Text("Total"))), TableCell(child: Center(child: Text("Total"))),
] ]
) )

View file

@ -1,4 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:pizzaplanner/entities/PizzaRecipe/Ingredient.dart'; import 'package:pizzaplanner/entities/PizzaRecipe/Ingredient.dart';
import 'package:pizzaplanner/entities/PizzaRecipe/Ingredients.dart'; import 'package:pizzaplanner/entities/PizzaRecipe/Ingredients.dart';
@ -11,6 +12,7 @@ class PizzaRecipe {
final String name; final String name;
final String description; final String description;
final Ingredients ingredients; final Ingredients ingredients;
final DateFormat dateFormatter = DateFormat("yyyy-MM-dd H:mm");
final List<RecipeStep> recipeSteps; final List<RecipeStep> recipeSteps;
@ -81,8 +83,47 @@ class PizzaRecipe {
); );
} }
Duration getMinDuration(){
return Duration(seconds: recipeSteps.map((recipeStep) => recipeStep.getWaitMinInSeconds()).reduce((a, b) => a+b));
}
Duration getCurrentDuration(){
return Duration(seconds: recipeSteps.map((recipeStep) => recipeStep.getCurrentWaitInSeconds()).reduce((a, b) => a+b));
}
String toString() { String toString() {
return "PizzaRecipe(${this.name}, ${this.ingredients.ingredients.length}, ${this.recipeSteps.length})"; return "PizzaRecipe(${this.name}, ${this.ingredients.ingredients.length}, ${this.recipeSteps.length})";
} }
Table getStepTimeTable(DateTime startTime) {
List<TableRow> stepRows = [];
DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(startTime.millisecondsSinceEpoch);
for (var recipeStep in this.recipeSteps.reversed) {
Duration stepWaitDuration = Duration(seconds: recipeStep.getCurrentWaitInSeconds());
stepRows.add(
TableRow(
children: <TableCell>[
TableCell(child: Center(child: Text(recipeStep.name))),
TableCell(child: Center(child: Text(dateFormatter.format(dateTime.subtract(stepWaitDuration)))))
]
)
);
dateTime = dateTime.subtract(stepWaitDuration);
}
return Table(
columnWidths: const <int, TableColumnWidth>{
0: FlexColumnWidth(1),
1: FlexColumnWidth(1),
},
children: <TableRow>[
TableRow(
children: <TableCell>[
TableCell(child: Center(child: Text("Step"))),
TableCell(child: Center(child: Text("When"))),
]
)
] + stepRows.reversed.toList()
);
}
} }

View file

@ -13,4 +13,33 @@ class RecipeStep {
RecipeStep(this.name, this.description, this.waitDescription, this.waitUnit, this.waitMin, this.waitMax, this.subSteps) { RecipeStep(this.name, this.description, this.waitDescription, this.waitUnit, this.waitMin, this.waitMax, this.subSteps) {
waitValue = waitMin; waitValue = waitMin;
} }
int convertToSeconds(int value){
switch (waitUnit){
case "minutes": {
return value * 60;
}
case "hours": {
return value * 60 * 60;
}
case "days": {
return value * 60 * 60 * 24;
}
default: {
return value;
}
}
}
int getWaitMinInSeconds(){
return convertToSeconds(this.waitMin);
}
int getWaitMaxInSeconds() {
return convertToSeconds(this.waitMax);
}
int getCurrentWaitInSeconds() {
return convertToSeconds(this.waitValue);
}
} }

View file

@ -1,6 +1,5 @@
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_datetime_picker/flutter_datetime_picker.dart'; import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
import 'package:fluttericon/font_awesome5_icons.dart'; import 'package:fluttericon/font_awesome5_icons.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
@ -14,8 +13,6 @@ class AddPizzaEventPage extends StatefulWidget {
} }
class AddPizzaEventPageState extends State<AddPizzaEventPage> { class AddPizzaEventPageState extends State<AddPizzaEventPage> {
final DateFormat dateFormatter = DateFormat("yyyy-MM-dd hh:mm");
String name = ""; String name = "";
bool initialized = false; bool initialized = false;
late PizzaRecipe pizzaRecipe; late PizzaRecipe pizzaRecipe;
@ -52,7 +49,7 @@ class AddPizzaEventPageState extends State<AddPizzaEventPage> {
child: Column( child: Column(
children: <Widget>[ children: <Widget>[
Expanded( Expanded(
flex: 30, flex: 35,
child: Column( child: Column(
children: <Widget>[ children: <Widget>[
Row( Row(
@ -137,29 +134,6 @@ class AddPizzaEventPageState extends State<AddPizzaEventPage> {
) )
] ]
), ),
Row(
children: <Widget>[
Icon(FontAwesome5.calendar_alt),
Expanded(
child: InkWell(
child: Center(
child: Text(dateFormatter.format(this.eventTime)),
),
onTap: () {
DatePicker.showDateTimePicker(context,
showTitleActions: true,
minTime: DateTime.now(),
currentTime: this.eventTime.difference(DateTime.now()).isNegative ? DateTime.now() : this.eventTime,
maxTime: DateTime.now().add(Duration(days: 365*10)),
onConfirm: (newEventTime) {
setState((){ this.eventTime = newEventTime; });
}
);
}
)
)
]
),
] ]
) )
), ),
@ -181,7 +155,7 @@ class AddPizzaEventPageState extends State<AddPizzaEventPage> {
max: recipeStep.waitMax.toDouble(), max: recipeStep.waitMax.toDouble(),
divisions: recipeStep.waitMax - recipeStep.waitMin, divisions: recipeStep.waitMax - recipeStep.waitMin,
label: recipeStep.waitValue.toString(), label: recipeStep.waitValue.toString(),
onChanged: (newValue) => setState(() => recipeStep.waitValue = newValue.toInt()), onChanged: (newValue) => this.setState(() => recipeStep.waitValue = newValue.toInt()),
) )
), ),
Container( Container(
@ -193,8 +167,6 @@ class AddPizzaEventPageState extends State<AddPizzaEventPage> {
]; ];
}).expand((option) => option).toList() }).expand((option) => option).toList()
) : Container(), ) : Container(),
Divider(),
this.initialized ? this.pizzaRecipe.getIngredientsTable(this.pizzaCount, this.doughBallSize) : Container(),
] ]
) )
), ),
@ -206,18 +178,24 @@ class AddPizzaEventPageState extends State<AddPizzaEventPage> {
child: Container( child: Container(
color: Colors.blue, color: Colors.blue,
child: TextButton( child: TextButton(
child: Text("Add", style: TextStyle(color: Colors.white)), child: Text("Review", style: TextStyle(color: Colors.white)),
onPressed: () { onPressed: () async {
if (this.name.length == 0){ if (this.name.length == 0){
setState(() { this.nameValidation = true; }); setState(() { this.nameValidation = true; });
return; return;
} }
DateTime eventTime = await showDialog(
context: context,
builder: (context) {
return ConfirmPizzaEventDialog(name: name, pizzaRecipe: pizzaRecipe, pizzaCount: pizzaCount, doughBallSize: doughBallSize);
}
);
Navigator.pop(context, PizzaEvent( Navigator.pop(context, PizzaEvent(
this.name, this.name,
this.pizzaRecipe, this.pizzaRecipe,
this.pizzaCount, this.pizzaCount,
this.doughBallSize, this.doughBallSize,
this.eventTime eventTime
)); ));
}, },
) )
@ -228,4 +206,113 @@ class AddPizzaEventPageState extends State<AddPizzaEventPage> {
) )
); );
} }
}
class ConfirmPizzaEventDialog extends StatefulWidget {
final String name;
final PizzaRecipe pizzaRecipe;
final int pizzaCount;
final int doughBallSize;
const ConfirmPizzaEventDialog({Key? key,
required this.name,
required this.pizzaRecipe,
required this.pizzaCount,
required this.doughBallSize}
) : super(key: key);
@override
ConfirmPizzaEventState createState() => new ConfirmPizzaEventState();
}
class ConfirmPizzaEventState extends State<ConfirmPizzaEventDialog> {
final DateFormat dateFormatter = DateFormat("yyyy-MM-dd H:mm");
late DateTime eventTime;
late final DateTime minTime;
@override
void initState() {
super.initState();
eventTime = DateTime.now().add(widget.pizzaRecipe.getCurrentDuration()).add(Duration(minutes: 1));
minTime = DateTime.now().add(widget.pizzaRecipe.getCurrentDuration());
}
@override
Widget build(BuildContext context){
return Dialog(
child: Container(
padding: EdgeInsets.all(10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Expanded(
flex: 30,
child: Column(
children: <Widget>[
Text(widget.name),
Divider(),
Text("Ingredients"),
widget.pizzaRecipe.getIngredientsTable(widget.pizzaCount, widget.doughBallSize),
Divider(),
SizedBox(
width: double.infinity,
height: 50,
child: Container(
color: Colors.blue,
child: TextButton(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(FontAwesome5.calendar_alt, color: Colors.white),
SizedBox(width: 10),
Text(dateFormatter.format(this.eventTime), style: TextStyle(color: Colors.white, fontSize: 25)),
]
),
onPressed: () {
DatePicker.showDateTimePicker(context,
showTitleActions: true,
minTime: minTime,
currentTime: eventTime,
maxTime: DateTime.now().add(Duration(days: 365*10)),
onConfirm: (newEventTime) {
setState((){ this.eventTime = newEventTime; });
print(dateFormatter.format(newEventTime));
}
);
}
)
)
),
]
)
),
Expanded(
flex: 60,
child: ListView(
children: <Widget>[
widget.pizzaRecipe.getStepTimeTable(eventTime)
]
)
),
Expanded(
flex: 10,
child: SizedBox(
width: double.infinity,
height: 70,
child: Container(
color: Colors.blue,
child: TextButton(
child: Text("Confirm", style: TextStyle(color: Colors.white)),
onPressed: () async {
Navigator.pop(context, this.eventTime);
},
)
)
)
),
]
)
)
);
}
} }