added a pick recipe page before add event page, removing the need for a 'complicated' dropdown on the event page
This commit is contained in:
parent
02691290e6
commit
1cce0767c0
6 changed files with 229 additions and 174 deletions
|
@ -109,6 +109,10 @@ class PizzaRecipe extends HiveObject {
|
||||||
return Duration(seconds: recipeSteps.map((recipeStep) => recipeStep.getWaitMinInSeconds()).reduce((a, b) => a+b));
|
return Duration(seconds: recipeSteps.map((recipeStep) => recipeStep.getWaitMinInSeconds()).reduce((a, b) => a+b));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Duration getMaxDuration(){
|
||||||
|
return Duration(seconds: recipeSteps.map((recipeStep) => recipeStep.getWaitMaxInSeconds()).reduce((a, b) => a+b));
|
||||||
|
}
|
||||||
|
|
||||||
Duration getCurrentDuration(){
|
Duration getCurrentDuration(){
|
||||||
return Duration(seconds: recipeSteps.map((recipeStep) => recipeStep.getCurrentWaitInSeconds()).reduce((a, b) => a+b));
|
return Duration(seconds: recipeSteps.map((recipeStep) => recipeStep.getCurrentWaitInSeconds()).reduce((a, b) => a+b));
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import 'package:pizzaplanner/entities/PizzaRecipe/PizzaRecipe.dart';
|
||||||
import 'package:pizzaplanner/entities/PizzaRecipe/RecipeStep.dart';
|
import 'package:pizzaplanner/entities/PizzaRecipe/RecipeStep.dart';
|
||||||
import 'package:pizzaplanner/entities/PizzaRecipe/RecipeSubStep.dart';
|
import 'package:pizzaplanner/entities/PizzaRecipe/RecipeSubStep.dart';
|
||||||
import 'package:pizzaplanner/pages/AddPizzaEventPage.dart';
|
import 'package:pizzaplanner/pages/AddPizzaEventPage.dart';
|
||||||
|
import 'package:pizzaplanner/pages/PickPizzaRecipePage.dart';
|
||||||
import 'package:pizzaplanner/pages/PizzaEventsPage.dart';
|
import 'package:pizzaplanner/pages/PizzaEventsPage.dart';
|
||||||
|
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive/hive.dart';
|
||||||
|
@ -50,8 +51,11 @@ class RouteGenerator {
|
||||||
case "/": {
|
case "/": {
|
||||||
return MaterialPageRoute(builder: (context) => PizzaEventsPage());
|
return MaterialPageRoute(builder: (context) => PizzaEventsPage());
|
||||||
}
|
}
|
||||||
case "/add": {
|
case "/event/pick_recipe": {
|
||||||
return MaterialPageRoute(builder: (context) => AddPizzaEventPage());
|
return MaterialPageRoute(builder: (context) => PickPizzaRecipePage());
|
||||||
|
}
|
||||||
|
case "/event/add": {
|
||||||
|
return MaterialPageRoute(builder: (context) => AddPizzaEventPage(settings.arguments as PizzaRecipe));
|
||||||
}
|
}
|
||||||
|
|
||||||
default: {
|
default: {
|
||||||
|
|
|
@ -11,14 +11,16 @@ import 'package:hive/hive.dart';
|
||||||
import 'package:hive_flutter/hive_flutter.dart';
|
import 'package:hive_flutter/hive_flutter.dart';
|
||||||
|
|
||||||
class AddPizzaEventPage extends StatefulWidget {
|
class AddPizzaEventPage extends StatefulWidget {
|
||||||
|
final PizzaRecipe pizzaRecipe;
|
||||||
|
|
||||||
|
AddPizzaEventPage(this.pizzaRecipe);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
AddPizzaEventPageState createState() => AddPizzaEventPageState();
|
AddPizzaEventPageState createState() => AddPizzaEventPageState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class AddPizzaEventPageState extends State<AddPizzaEventPage> {
|
class AddPizzaEventPageState extends State<AddPizzaEventPage> {
|
||||||
String name = "";
|
String name = "";
|
||||||
bool initialized = false;
|
|
||||||
late PizzaRecipe pizzaRecipe;
|
|
||||||
int pizzaCount = 1;
|
int pizzaCount = 1;
|
||||||
int doughBallSize = 250;
|
int doughBallSize = 250;
|
||||||
DateTime eventTime = DateTime.now();
|
DateTime eventTime = DateTime.now();
|
||||||
|
@ -35,179 +37,151 @@ class AddPizzaEventPageState extends State<AddPizzaEventPage> {
|
||||||
body: Container(
|
body: Container(
|
||||||
padding: EdgeInsets.fromLTRB(40, 10, 40, 10),
|
padding: EdgeInsets.fromLTRB(40, 10, 40, 10),
|
||||||
child: Column(
|
child: Column(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Expanded(
|
Expanded(
|
||||||
flex: 35,
|
flex: 20,
|
||||||
child: Column(
|
child: Column(
|
||||||
children: <Widget>[
|
|
||||||
Row(
|
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Icon(Icons.title),
|
Row(
|
||||||
Container(width: 25),
|
children: <Widget>[
|
||||||
Expanded(
|
Icon(Icons.title),
|
||||||
child: TextField(
|
Container(width: 25),
|
||||||
decoration: InputDecoration(
|
Expanded(
|
||||||
hintText: "Event Name",
|
child: TextField(
|
||||||
errorText: this.nameValidation ? "Name can\'t be empty" : null
|
decoration: InputDecoration(
|
||||||
),
|
hintText: "Event Name",
|
||||||
onChanged: (String newName) {
|
errorText: this.nameValidation ? "Name can\'t be empty" : null
|
||||||
setState(() {
|
),
|
||||||
name = newName;
|
onChanged: (String newName) {
|
||||||
});
|
setState(() {
|
||||||
},
|
name = newName;
|
||||||
),
|
});
|
||||||
)
|
},
|
||||||
]
|
|
||||||
),
|
|
||||||
Row(
|
|
||||||
children: <Widget>[
|
|
||||||
Icon(FontAwesome5.pizza_slice),
|
|
||||||
Container(width: 25),
|
|
||||||
ValueListenableBuilder(
|
|
||||||
valueListenable: Hive.box<PizzaRecipe>("PizzaRecipes").listenable(),
|
|
||||||
builder: (context, Box<PizzaRecipe> box, widget) {
|
|
||||||
if (box.isEmpty){
|
|
||||||
return Text("Loading Pizza Recipes...");
|
|
||||||
}
|
|
||||||
this.pizzaRecipe = box.values.first;
|
|
||||||
return Expanded(
|
|
||||||
child: DropdownButton<String>(
|
|
||||||
value: this.pizzaRecipe.name,
|
|
||||||
onChanged: (String? newType) {
|
|
||||||
setState(() => this.pizzaRecipe = box.values.firstWhere((pizzaRecipe) => pizzaRecipe.name == newType));
|
|
||||||
},
|
|
||||||
items: box.values.map((pizzaRecipe) {
|
|
||||||
return DropdownMenuItem(
|
|
||||||
value: pizzaRecipe.name,
|
|
||||||
child: Text(pizzaRecipe.name)
|
|
||||||
);
|
|
||||||
}).toList()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
),
|
|
||||||
]
|
|
||||||
),
|
|
||||||
Row(
|
|
||||||
children: <Widget>[
|
|
||||||
Icon(FontAwesome5.hashtag),
|
|
||||||
Expanded(
|
|
||||||
child: Slider(
|
|
||||||
value: pizzaCount.toDouble(),
|
|
||||||
min: 1,
|
|
||||||
max: 20,
|
|
||||||
divisions: 19,
|
|
||||||
label: this.pizzaCount.toString(),
|
|
||||||
onChanged: (double newPizzaCount) {
|
|
||||||
setState(() {this.pizzaCount = newPizzaCount.round();});
|
|
||||||
},
|
|
||||||
)
|
|
||||||
),
|
|
||||||
Container(
|
|
||||||
width: 25,
|
|
||||||
child: Text(this.pizzaCount.toString())
|
|
||||||
)
|
|
||||||
]
|
|
||||||
),
|
|
||||||
Row(
|
|
||||||
children: <Widget>[
|
|
||||||
Icon(FontAwesome5.weight_hanging),
|
|
||||||
Expanded(
|
|
||||||
child: Slider(
|
|
||||||
value: doughBallSize.toDouble(),
|
|
||||||
min: 100,
|
|
||||||
max: 400,
|
|
||||||
divisions: 30,
|
|
||||||
label: this.doughBallSize.toString(),
|
|
||||||
onChanged: (double newDoughBallSize) {
|
|
||||||
setState(() {this.doughBallSize = newDoughBallSize.round();});
|
|
||||||
},
|
|
||||||
)
|
|
||||||
),
|
|
||||||
Container(
|
|
||||||
width: 25,
|
|
||||||
child: Text(this.doughBallSize.toString())
|
|
||||||
)
|
|
||||||
]
|
|
||||||
),
|
|
||||||
]
|
|
||||||
)
|
|
||||||
),
|
|
||||||
Divider(),
|
|
||||||
Expanded(
|
|
||||||
flex: 45,
|
|
||||||
child: ListView(
|
|
||||||
children: <Widget>[
|
|
||||||
this.initialized ? Column(
|
|
||||||
children: this.pizzaRecipe.recipeSteps.where((recipeStep) => recipeStep.waitDescription.length > 0).map((recipeStep) {
|
|
||||||
return <Widget>[
|
|
||||||
Text(recipeStep.waitDescription),
|
|
||||||
Row(
|
|
||||||
children: <Widget>[
|
|
||||||
Expanded(
|
|
||||||
child: Slider(
|
|
||||||
value: recipeStep.waitValue!.toDouble(),
|
|
||||||
min: recipeStep.waitMin.toDouble(),
|
|
||||||
max: recipeStep.waitMax.toDouble(),
|
|
||||||
divisions: recipeStep.waitMax - recipeStep.waitMin,
|
|
||||||
label: recipeStep.waitValue.toString(),
|
|
||||||
onChanged: (newValue) => this.setState(() => recipeStep.waitValue = newValue.toInt()),
|
|
||||||
)
|
|
||||||
),
|
),
|
||||||
Container(
|
)
|
||||||
width: 25,
|
]
|
||||||
child: Text(recipeStep.waitValue.toString())
|
),
|
||||||
|
Row(
|
||||||
|
children: <Widget>[
|
||||||
|
Icon(FontAwesome5.hashtag),
|
||||||
|
Expanded(
|
||||||
|
child: Slider(
|
||||||
|
value: pizzaCount.toDouble(),
|
||||||
|
min: 1,
|
||||||
|
max: 20,
|
||||||
|
divisions: 19,
|
||||||
|
label: this.pizzaCount.toString(),
|
||||||
|
onChanged: (double newPizzaCount) {
|
||||||
|
setState(() {this.pizzaCount = newPizzaCount.round();});
|
||||||
|
},
|
||||||
|
)
|
||||||
|
),
|
||||||
|
Container(
|
||||||
|
width: 25,
|
||||||
|
child: Text(this.pizzaCount.toString())
|
||||||
|
)
|
||||||
|
]
|
||||||
|
),
|
||||||
|
Row(
|
||||||
|
children: <Widget>[
|
||||||
|
Icon(FontAwesome5.weight_hanging),
|
||||||
|
Expanded(
|
||||||
|
child: Slider(
|
||||||
|
value: doughBallSize.toDouble(),
|
||||||
|
min: 100,
|
||||||
|
max: 400,
|
||||||
|
divisions: 30,
|
||||||
|
label: this.doughBallSize.toString(),
|
||||||
|
onChanged: (double newDoughBallSize) {
|
||||||
|
setState(() {this.doughBallSize = newDoughBallSize.round();});
|
||||||
|
},
|
||||||
|
)
|
||||||
|
),
|
||||||
|
Container(
|
||||||
|
width: 25,
|
||||||
|
child: Text(this.doughBallSize.toString())
|
||||||
|
)
|
||||||
|
]
|
||||||
|
),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
),
|
||||||
|
Divider(),
|
||||||
|
Expanded(
|
||||||
|
flex: 45,
|
||||||
|
child: ListView(
|
||||||
|
children: <Widget>[
|
||||||
|
Column(
|
||||||
|
children: this.widget.pizzaRecipe.recipeSteps.where((recipeStep) => recipeStep.waitDescription.length > 0).map((recipeStep) {
|
||||||
|
return <Widget>[
|
||||||
|
Text(recipeStep.waitDescription),
|
||||||
|
Row(
|
||||||
|
children: <Widget>[
|
||||||
|
Expanded(
|
||||||
|
child: Slider(
|
||||||
|
value: recipeStep.waitValue!.toDouble(),
|
||||||
|
min: recipeStep.waitMin.toDouble(),
|
||||||
|
max: recipeStep.waitMax.toDouble(),
|
||||||
|
divisions: recipeStep.waitMax - recipeStep.waitMin,
|
||||||
|
label: recipeStep.waitValue.toString(),
|
||||||
|
onChanged: (newValue) => this.setState(() => recipeStep.waitValue = newValue.toInt()),
|
||||||
|
)
|
||||||
|
),
|
||||||
|
Container(
|
||||||
|
width: 25,
|
||||||
|
child: Text(recipeStep.waitValue.toString())
|
||||||
|
)
|
||||||
|
]
|
||||||
)
|
)
|
||||||
]
|
];
|
||||||
)
|
}).expand((option) => option).toList()
|
||||||
];
|
)
|
||||||
}).expand((option) => option).toList()
|
]
|
||||||
) : Container(),
|
)
|
||||||
]
|
),
|
||||||
)
|
Divider(),
|
||||||
),
|
Spacer(),
|
||||||
Divider(),
|
SizedBox(
|
||||||
Spacer(),
|
width: double.infinity,
|
||||||
SizedBox(
|
height: 70,
|
||||||
width: double.infinity,
|
child: Container(
|
||||||
height: 70,
|
color: Colors.blue,
|
||||||
child: Container(
|
child: TextButton(
|
||||||
color: Colors.blue,
|
child: Text("Review", style: TextStyle(color: Colors.white)),
|
||||||
child: TextButton(
|
onPressed: () async {
|
||||||
child: Text("Review", style: TextStyle(color: Colors.white)),
|
if (this.name.length == 0){
|
||||||
onPressed: () async {
|
setState(() { this.nameValidation = true; });
|
||||||
if (this.name.length == 0){
|
return;
|
||||||
setState(() { this.nameValidation = true; });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
setState(() { this.nameValidation = false; });
|
|
||||||
FocusScope.of(context).unfocus();
|
|
||||||
DateTime? eventTime = await showDialog(
|
|
||||||
context: context,
|
|
||||||
builder: (context) {
|
|
||||||
return ConfirmPizzaEventDialog(name: name, pizzaRecipe: pizzaRecipe, pizzaCount: pizzaCount, doughBallSize: doughBallSize);
|
|
||||||
}
|
}
|
||||||
);
|
setState(() { this.nameValidation = false; });
|
||||||
if (eventTime == null){
|
FocusScope.of(context).unfocus();
|
||||||
return;
|
DateTime? eventTime = await showDialog(
|
||||||
}
|
context: context,
|
||||||
var pizzaEventsBox = await Hive.box<PizzaEvent>("PizzaEvents");
|
builder: (context) {
|
||||||
pizzaEventsBox.add(
|
return ConfirmPizzaEventDialog(name: name, pizzaRecipe: this.widget.pizzaRecipe, pizzaCount: pizzaCount, doughBallSize: doughBallSize);
|
||||||
PizzaEvent(
|
}
|
||||||
this.name,
|
);
|
||||||
this.pizzaRecipe,
|
if (eventTime == null){
|
||||||
this.pizzaCount,
|
return;
|
||||||
this.doughBallSize,
|
}
|
||||||
eventTime
|
var pizzaEventsBox = await Hive.box<PizzaEvent>("PizzaEvents");
|
||||||
)
|
pizzaEventsBox.add(
|
||||||
);
|
PizzaEvent(
|
||||||
Navigator.pop(context);
|
this.name,
|
||||||
},
|
this.widget.pizzaRecipe,
|
||||||
)
|
this.pizzaCount,
|
||||||
)
|
this.doughBallSize,
|
||||||
)
|
eventTime
|
||||||
]
|
)
|
||||||
)
|
);
|
||||||
|
Navigator.pop(context);
|
||||||
|
Navigator.pop(context); // two times because of the pick recipe page
|
||||||
|
},
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -244,6 +218,7 @@ class ConfirmPizzaEventState extends State<ConfirmPizzaEventDialog> {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context){
|
Widget build(BuildContext context){
|
||||||
return Dialog(
|
return Dialog(
|
||||||
|
insetPadding: EdgeInsets.all(10),
|
||||||
child: Container(
|
child: Container(
|
||||||
padding: EdgeInsets.all(10),
|
padding: EdgeInsets.all(10),
|
||||||
child: Column(
|
child: Column(
|
||||||
|
|
30
lib/pages/PickPizzaRecipePage.dart
Normal file
30
lib/pages/PickPizzaRecipePage.dart
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:hive_flutter/adapters.dart';
|
||||||
|
import 'package:pizzaplanner/entities/PizzaRecipe/PizzaRecipe.dart';
|
||||||
|
import 'package:pizzaplanner/widgets/PizzaRecipeWidget.dart';
|
||||||
|
|
||||||
|
class PickPizzaRecipePage extends StatelessWidget {
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context){
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
title: Text("Pick Pizza Recipe"),
|
||||||
|
),
|
||||||
|
resizeToAvoidBottomInset: false,
|
||||||
|
body: Container(
|
||||||
|
padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
|
||||||
|
child: ValueListenableBuilder(
|
||||||
|
valueListenable: Hive.box<PizzaRecipe>("PizzaRecipes").listenable(),
|
||||||
|
builder: (context, Box<PizzaRecipe> pizzaRecipesBox, widget) {
|
||||||
|
return ListView.separated(
|
||||||
|
padding: const EdgeInsets.all(8),
|
||||||
|
itemCount: pizzaRecipesBox.length,
|
||||||
|
itemBuilder: (context, i) => PizzaRecipeWidget(pizzaRecipesBox.getAt(i)!),
|
||||||
|
separatorBuilder: (BuildContext context, int i) => const Divider(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -42,7 +42,7 @@ class PizzaEventsState extends State<PizzaEventsPage> {
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
final dynamic newPizzaEvent = await Navigator.pushNamed(
|
final dynamic newPizzaEvent = await Navigator.pushNamed(
|
||||||
context,
|
context,
|
||||||
"/add",
|
"/event/pick_recipe",
|
||||||
);
|
);
|
||||||
|
|
||||||
if (newPizzaEvent != null){
|
if (newPizzaEvent != null){
|
||||||
|
|
42
lib/widgets/PizzaRecipeWidget.dart
Normal file
42
lib/widgets/PizzaRecipeWidget.dart
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:pizzaplanner/entities/PizzaRecipe/PizzaRecipe.dart';
|
||||||
|
|
||||||
|
class PizzaRecipeWidget extends StatelessWidget {
|
||||||
|
final PizzaRecipe pizzaRecipe;
|
||||||
|
|
||||||
|
PizzaRecipeWidget(this.pizzaRecipe);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return InkWell(
|
||||||
|
child: Container(
|
||||||
|
height: 120,
|
||||||
|
color: Colors.blueAccent,
|
||||||
|
child: Container(
|
||||||
|
padding: const EdgeInsets.all(8),
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: <Widget>[
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: <Widget>[
|
||||||
|
Text(pizzaRecipe.name),
|
||||||
|
]
|
||||||
|
),
|
||||||
|
Text(pizzaRecipe.description),
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: <Widget>[
|
||||||
|
Text("${pizzaRecipe.getMinDuration().inHours.round()} to ${pizzaRecipe.getMaxDuration().inHours.round()} hours")
|
||||||
|
]
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
onTap: () {
|
||||||
|
Navigator.pushNamed(context, "/event/add", arguments: this.pizzaRecipe);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue