diff --git a/lib/entities/PizzaRecipe/Ingredients.dart b/lib/entities/PizzaRecipe/Ingredients.dart index 7578baa..a00d7e8 100644 --- a/lib/entities/PizzaRecipe/Ingredients.dart +++ b/lib/entities/PizzaRecipe/Ingredients.dart @@ -12,15 +12,14 @@ class Ingredients { border: TableBorder.all(), columnWidths: const { 0: FlexColumnWidth(2), - 1: FlexColumnWidth(2), + 1: FlexColumnWidth(1), 2: FlexColumnWidth(2), }, - children: - [ + children: [ TableRow( children: [ 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"))), ] ) diff --git a/lib/entities/PizzaRecipe/PizzaRecipe.dart b/lib/entities/PizzaRecipe/PizzaRecipe.dart index 7744402..8d2575a 100644 --- a/lib/entities/PizzaRecipe/PizzaRecipe.dart +++ b/lib/entities/PizzaRecipe/PizzaRecipe.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:intl/intl.dart'; import 'package:pizzaplanner/entities/PizzaRecipe/Ingredient.dart'; import 'package:pizzaplanner/entities/PizzaRecipe/Ingredients.dart'; @@ -11,6 +12,7 @@ class PizzaRecipe { final String name; final String description; final Ingredients ingredients; + final DateFormat dateFormatter = DateFormat("yyyy-MM-dd H:mm"); final List 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() { return "PizzaRecipe(${this.name}, ${this.ingredients.ingredients.length}, ${this.recipeSteps.length})"; } + + Table getStepTimeTable(DateTime startTime) { + List 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(child: Center(child: Text(recipeStep.name))), + TableCell(child: Center(child: Text(dateFormatter.format(dateTime.subtract(stepWaitDuration))))) + ] + ) + ); + dateTime = dateTime.subtract(stepWaitDuration); + } + return Table( + columnWidths: const { + 0: FlexColumnWidth(1), + 1: FlexColumnWidth(1), + }, + children: [ + TableRow( + children: [ + TableCell(child: Center(child: Text("Step"))), + TableCell(child: Center(child: Text("When"))), + ] + ) + ] + stepRows.reversed.toList() + ); + } } diff --git a/lib/entities/PizzaRecipe/RecipeStep.dart b/lib/entities/PizzaRecipe/RecipeStep.dart index 4c4b8b3..8de8b1b 100644 --- a/lib/entities/PizzaRecipe/RecipeStep.dart +++ b/lib/entities/PizzaRecipe/RecipeStep.dart @@ -13,4 +13,33 @@ class RecipeStep { RecipeStep(this.name, this.description, this.waitDescription, this.waitUnit, this.waitMin, this.waitMax, this.subSteps) { 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); + } } \ No newline at end of file diff --git a/lib/pages/AddPizzaEventPage.dart b/lib/pages/AddPizzaEventPage.dart index b6f8d06..09abc64 100644 --- a/lib/pages/AddPizzaEventPage.dart +++ b/lib/pages/AddPizzaEventPage.dart @@ -1,6 +1,5 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; import 'package:flutter_datetime_picker/flutter_datetime_picker.dart'; import 'package:fluttericon/font_awesome5_icons.dart'; import 'package:intl/intl.dart'; @@ -14,8 +13,6 @@ class AddPizzaEventPage extends StatefulWidget { } class AddPizzaEventPageState extends State { - final DateFormat dateFormatter = DateFormat("yyyy-MM-dd hh:mm"); - String name = ""; bool initialized = false; late PizzaRecipe pizzaRecipe; @@ -52,7 +49,7 @@ class AddPizzaEventPageState extends State { child: Column( children: [ Expanded( - flex: 30, + flex: 35, child: Column( children: [ Row( @@ -137,29 +134,6 @@ class AddPizzaEventPageState extends State { ) ] ), - Row( - children: [ - 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 { max: recipeStep.waitMax.toDouble(), divisions: recipeStep.waitMax - recipeStep.waitMin, label: recipeStep.waitValue.toString(), - onChanged: (newValue) => setState(() => recipeStep.waitValue = newValue.toInt()), + onChanged: (newValue) => this.setState(() => recipeStep.waitValue = newValue.toInt()), ) ), Container( @@ -193,8 +167,6 @@ class AddPizzaEventPageState extends State { ]; }).expand((option) => option).toList() ) : Container(), - Divider(), - this.initialized ? this.pizzaRecipe.getIngredientsTable(this.pizzaCount, this.doughBallSize) : Container(), ] ) ), @@ -206,18 +178,24 @@ class AddPizzaEventPageState extends State { child: Container( color: Colors.blue, child: TextButton( - child: Text("Add", style: TextStyle(color: Colors.white)), - onPressed: () { + child: Text("Review", style: TextStyle(color: Colors.white)), + onPressed: () async { if (this.name.length == 0){ setState(() { this.nameValidation = true; }); return; } + DateTime eventTime = await showDialog( + context: context, + builder: (context) { + return ConfirmPizzaEventDialog(name: name, pizzaRecipe: pizzaRecipe, pizzaCount: pizzaCount, doughBallSize: doughBallSize); + } + ); Navigator.pop(context, PizzaEvent( this.name, this.pizzaRecipe, this.pizzaCount, this.doughBallSize, - this.eventTime + eventTime )); }, ) @@ -228,4 +206,113 @@ class AddPizzaEventPageState extends State { ) ); } +} + +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 { + 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: [ + Expanded( + flex: 30, + child: Column( + children: [ + 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: [ + 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.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); + }, + ) + ) + ) + ), + ] + ) + ) + ); + } } \ No newline at end of file