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:
broodjeaap89 2021-07-27 20:34:50 +02:00
parent 02691290e6
commit 1cce0767c0
6 changed files with 229 additions and 174 deletions

View file

@ -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));
} }

View file

@ -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: {

View file

@ -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();
@ -37,7 +39,7 @@ class AddPizzaEventPageState extends State<AddPizzaEventPage> {
child: Column( child: Column(
children: <Widget>[ children: <Widget>[
Expanded( Expanded(
flex: 35, flex: 20,
child: Column( child: Column(
children: <Widget>[ children: <Widget>[
Row( Row(
@ -59,35 +61,6 @@ class AddPizzaEventPageState extends State<AddPizzaEventPage> {
) )
] ]
), ),
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( Row(
children: <Widget>[ children: <Widget>[
Icon(FontAwesome5.hashtag), Icon(FontAwesome5.hashtag),
@ -138,8 +111,8 @@ class AddPizzaEventPageState extends State<AddPizzaEventPage> {
flex: 45, flex: 45,
child: ListView( child: ListView(
children: <Widget>[ children: <Widget>[
this.initialized ? Column( Column(
children: this.pizzaRecipe.recipeSteps.where((recipeStep) => recipeStep.waitDescription.length > 0).map((recipeStep) { children: this.widget.pizzaRecipe.recipeSteps.where((recipeStep) => recipeStep.waitDescription.length > 0).map((recipeStep) {
return <Widget>[ return <Widget>[
Text(recipeStep.waitDescription), Text(recipeStep.waitDescription),
Row( Row(
@ -162,7 +135,7 @@ class AddPizzaEventPageState extends State<AddPizzaEventPage> {
) )
]; ];
}).expand((option) => option).toList() }).expand((option) => option).toList()
) : Container(), )
] ]
) )
), ),
@ -185,7 +158,7 @@ class AddPizzaEventPageState extends State<AddPizzaEventPage> {
DateTime? eventTime = await showDialog( DateTime? eventTime = await showDialog(
context: context, context: context,
builder: (context) { builder: (context) {
return ConfirmPizzaEventDialog(name: name, pizzaRecipe: pizzaRecipe, pizzaCount: pizzaCount, doughBallSize: doughBallSize); return ConfirmPizzaEventDialog(name: name, pizzaRecipe: this.widget.pizzaRecipe, pizzaCount: pizzaCount, doughBallSize: doughBallSize);
} }
); );
if (eventTime == null){ if (eventTime == null){
@ -195,13 +168,14 @@ class AddPizzaEventPageState extends State<AddPizzaEventPage> {
pizzaEventsBox.add( pizzaEventsBox.add(
PizzaEvent( PizzaEvent(
this.name, this.name,
this.pizzaRecipe, this.widget.pizzaRecipe,
this.pizzaCount, this.pizzaCount,
this.doughBallSize, this.doughBallSize,
eventTime eventTime
) )
); );
Navigator.pop(context); 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(

View 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(),
);
}
)
)
);
}
}

View file

@ -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){

View 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);
},
);
}
}