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));
}
Duration getMaxDuration(){
return Duration(seconds: recipeSteps.map((recipeStep) => recipeStep.getWaitMaxInSeconds()).reduce((a, b) => a+b));
}
Duration getCurrentDuration(){
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/RecipeSubStep.dart';
import 'package:pizzaplanner/pages/AddPizzaEventPage.dart';
import 'package:pizzaplanner/pages/PickPizzaRecipePage.dart';
import 'package:pizzaplanner/pages/PizzaEventsPage.dart';
import 'package:hive/hive.dart';
@ -50,8 +51,11 @@ class RouteGenerator {
case "/": {
return MaterialPageRoute(builder: (context) => PizzaEventsPage());
}
case "/add": {
return MaterialPageRoute(builder: (context) => AddPizzaEventPage());
case "/event/pick_recipe": {
return MaterialPageRoute(builder: (context) => PickPizzaRecipePage());
}
case "/event/add": {
return MaterialPageRoute(builder: (context) => AddPizzaEventPage(settings.arguments as PizzaRecipe));
}
default: {

View file

@ -11,14 +11,16 @@ import 'package:hive/hive.dart';
import 'package:hive_flutter/hive_flutter.dart';
class AddPizzaEventPage extends StatefulWidget {
final PizzaRecipe pizzaRecipe;
AddPizzaEventPage(this.pizzaRecipe);
@override
AddPizzaEventPageState createState() => AddPizzaEventPageState();
}
class AddPizzaEventPageState extends State<AddPizzaEventPage> {
String name = "";
bool initialized = false;
late PizzaRecipe pizzaRecipe;
int pizzaCount = 1;
int doughBallSize = 250;
DateTime eventTime = DateTime.now();
@ -37,7 +39,7 @@ class AddPizzaEventPageState extends State<AddPizzaEventPage> {
child: Column(
children: <Widget>[
Expanded(
flex: 35,
flex: 20,
child: Column(
children: <Widget>[
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(
children: <Widget>[
Icon(FontAwesome5.hashtag),
@ -138,8 +111,8 @@ class AddPizzaEventPageState extends State<AddPizzaEventPage> {
flex: 45,
child: ListView(
children: <Widget>[
this.initialized ? Column(
children: this.pizzaRecipe.recipeSteps.where((recipeStep) => recipeStep.waitDescription.length > 0).map((recipeStep) {
Column(
children: this.widget.pizzaRecipe.recipeSteps.where((recipeStep) => recipeStep.waitDescription.length > 0).map((recipeStep) {
return <Widget>[
Text(recipeStep.waitDescription),
Row(
@ -162,7 +135,7 @@ class AddPizzaEventPageState extends State<AddPizzaEventPage> {
)
];
}).expand((option) => option).toList()
) : Container(),
)
]
)
),
@ -185,7 +158,7 @@ class AddPizzaEventPageState extends State<AddPizzaEventPage> {
DateTime? eventTime = await showDialog(
context: 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){
@ -195,13 +168,14 @@ class AddPizzaEventPageState extends State<AddPizzaEventPage> {
pizzaEventsBox.add(
PizzaEvent(
this.name,
this.pizzaRecipe,
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
Widget build(BuildContext context){
return Dialog(
insetPadding: EdgeInsets.all(10),
child: Container(
padding: EdgeInsets.all(10),
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 {
final dynamic newPizzaEvent = await Navigator.pushNamed(
context,
"/add",
"/event/pick_recipe",
);
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);
},
);
}
}