so Floor just sucks? commit before reverting
This commit is contained in:
parent
1382a4a843
commit
914e17fa3c
11 changed files with 163 additions and 35 deletions
|
@ -433,7 +433,7 @@ class _$IngredientDao extends IngredientDao {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<List<Ingredient>> getPizzaRecipeSteps(int pizzaRecipeId) async {
|
Future<List<Ingredient>> getPizzaRecipeIngredients(int pizzaRecipeId) async {
|
||||||
return _queryAdapter.queryList(
|
return _queryAdapter.queryList(
|
||||||
'SELECT * FROM Ingredient WHERE pizzaRecipeId = ?1',
|
'SELECT * FROM Ingredient WHERE pizzaRecipeId = ?1',
|
||||||
mapper: (Map<String, Object?> row) => Ingredient(
|
mapper: (Map<String, Object?> row) => Ingredient(
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import 'package:floor/floor.dart';
|
import 'package:floor/floor.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:pizzaplanner/entities/PizzaDatabase.dart';
|
|
||||||
import 'package:pizzaplanner/util.dart';
|
import 'package:pizzaplanner/util.dart';
|
||||||
import 'package:pizzaplanner/entities/PizzaRecipe/Ingredient.dart';
|
import 'package:pizzaplanner/entities/PizzaRecipe/Ingredient.dart';
|
||||||
|
|
||||||
|
@ -17,9 +16,11 @@ class PizzaRecipe {
|
||||||
final String name;
|
final String name;
|
||||||
final String description;
|
final String description;
|
||||||
|
|
||||||
//final List<Ingredient> ingredients;
|
@ignore
|
||||||
|
List<Ingredient> ingredients = [];
|
||||||
|
|
||||||
//final List<RecipeStep> recipeSteps;
|
@ignore
|
||||||
|
List<RecipeStep> recipeSteps = [];
|
||||||
|
|
||||||
PizzaRecipe(this.name, this.description, {this.id});
|
PizzaRecipe(this.name, this.description, {this.id});
|
||||||
|
|
||||||
|
@ -36,9 +37,6 @@ class PizzaRecipe {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Table> getIngredientsTable(int pizzaCount, int doughBallSize) async {
|
Future<Table> getIngredientsTable(int pizzaCount, int doughBallSize) async {
|
||||||
final database = await getDatabase();
|
|
||||||
final ingredientDao = database.ingredientDao;
|
|
||||||
final ingredients = await ingredientDao.getPizzaRecipeSteps(this.id!);
|
|
||||||
return Table(
|
return Table(
|
||||||
border: TableBorder.all(),
|
border: TableBorder.all(),
|
||||||
columnWidths: const <int, TableColumnWidth>{
|
columnWidths: const <int, TableColumnWidth>{
|
||||||
|
@ -56,7 +54,7 @@ class PizzaRecipe {
|
||||||
)
|
)
|
||||||
|
|
||||||
] +
|
] +
|
||||||
ingredients.map((ingredient) =>
|
this.ingredients.map((ingredient) =>
|
||||||
ingredient.getIngredientTableRow(pizzaCount, doughBallSize))
|
ingredient.getIngredientTableRow(pizzaCount, doughBallSize))
|
||||||
.toList()
|
.toList()
|
||||||
);
|
);
|
||||||
|
@ -124,14 +122,16 @@ class PizzaRecipe {
|
||||||
return Tuple4(pizzaRecipe, ingredients, recipeSteps, recipeSubSteps);
|
return Tuple4(pizzaRecipe, ingredients, recipeSteps, recipeSubSteps);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Duration> getMinDuration() async {
|
Duration getMinDuration() {
|
||||||
List<RecipeStep> recipeSteps = await this.getRecipeSteps();
|
|
||||||
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));
|
||||||
|
}
|
||||||
|
|
||||||
Future<Duration> getCurrentDuration() async {
|
Future<Duration> getCurrentDuration() async {
|
||||||
List<RecipeStep> recipeSteps = await this.getRecipeSteps();
|
return Duration(seconds: this.recipeSteps.map((recipeStep) => recipeStep.getCurrentWaitInSeconds()).reduce((a, b) => a+b));
|
||||||
return Duration(seconds: recipeSteps.map((recipeStep) => recipeStep.getCurrentWaitInSeconds()).reduce((a, b) => a+b));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String toString() {
|
String toString() {
|
||||||
|
@ -141,8 +141,7 @@ class PizzaRecipe {
|
||||||
Future<Table> getStepTimeTable(DateTime startTime) async {
|
Future<Table> getStepTimeTable(DateTime startTime) async {
|
||||||
List<TableRow> stepRows = [];
|
List<TableRow> stepRows = [];
|
||||||
DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(startTime.millisecondsSinceEpoch);
|
DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(startTime.millisecondsSinceEpoch);
|
||||||
List<RecipeStep> recipeSteps = await this.getRecipeSteps();
|
for (var recipeStep in this.recipeSteps.reversed) {
|
||||||
for (var recipeStep in recipeSteps.reversed) {
|
|
||||||
Duration stepWaitDuration = Duration(seconds: recipeStep.getCurrentWaitInSeconds());
|
Duration stepWaitDuration = Duration(seconds: recipeStep.getCurrentWaitInSeconds());
|
||||||
stepRows.add(
|
stepRows.add(
|
||||||
TableRow(
|
TableRow(
|
||||||
|
|
|
@ -21,7 +21,8 @@ class RecipeStep {
|
||||||
late int waitValue;
|
late int waitValue;
|
||||||
final String description;
|
final String description;
|
||||||
|
|
||||||
// final List<RecipeSubStep> subSteps;
|
@ignore
|
||||||
|
List<RecipeSubStep> subSteps = [];
|
||||||
|
|
||||||
RecipeStep(this.pizzaRecipeId, this.name, this.description, this.waitDescription, this.waitUnit, this.waitMin, this.waitMax, {this.id}) {
|
RecipeStep(this.pizzaRecipeId, this.name, this.description, this.waitDescription, this.waitUnit, this.waitMin, this.waitMax, {this.id}) {
|
||||||
waitValue = waitMin;
|
waitValue = waitMin;
|
||||||
|
@ -61,10 +62,4 @@ class RecipeStep {
|
||||||
int getCurrentWaitInSeconds() {
|
int getCurrentWaitInSeconds() {
|
||||||
return convertToSeconds(this.waitValue);
|
return convertToSeconds(this.waitValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<List<RecipeStep>> getRecipeStepForRecipe(PizzaRecipe pizzaRecipe) async {
|
|
||||||
final database = await getDatabase();
|
|
||||||
final recipeStepDao = database.recipeStepDao;
|
|
||||||
return recipeStepDao.getPizzaRecipeSteps(pizzaRecipe.id!);
|
|
||||||
}
|
|
||||||
}
|
}
|
38
lib/entities/dao/AppDao.dart
Normal file
38
lib/entities/dao/AppDao.dart
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
import 'package:pizzaplanner/entities/PizzaDatabase.dart';
|
||||||
|
import 'package:pizzaplanner/entities/PizzaRecipe/PizzaRecipe.dart';
|
||||||
|
import 'package:pizzaplanner/util.dart';
|
||||||
|
|
||||||
|
|
||||||
|
class AppDao {
|
||||||
|
static const DATABASE_PATH = "pizza.db";
|
||||||
|
|
||||||
|
static Future<List<PizzaRecipe>> getPizzaRecipes() async {
|
||||||
|
final database = await $FloorPizzaDatabase.databaseBuilder(DATABASE_PATH).build();
|
||||||
|
final pizzaRecipeDao = database.pizzaRecipeDao;
|
||||||
|
final recipeStepDao = database.recipeStepDao;
|
||||||
|
final recipeSubStepDao = database.recipeSubStepDao;
|
||||||
|
final ingredientDao = database.ingredientDao;
|
||||||
|
|
||||||
|
List<PizzaRecipe> pizzaRecipes = await pizzaRecipeDao.getAllPizzaRecipes();
|
||||||
|
|
||||||
|
if (pizzaRecipes.isEmpty){
|
||||||
|
await loadYamlRecipesIntoDb();
|
||||||
|
pizzaRecipes = await pizzaRecipeDao.getAllPizzaRecipes();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var pizzaRecipe in pizzaRecipes) {
|
||||||
|
pizzaRecipe.ingredients = await ingredientDao.getPizzaRecipeIngredients(pizzaRecipe.id!);
|
||||||
|
print(pizzaRecipe.ingredients);
|
||||||
|
pizzaRecipe.recipeSteps = await recipeStepDao.getPizzaRecipeSteps(pizzaRecipe.id!);
|
||||||
|
print(pizzaRecipe.recipeSteps);
|
||||||
|
for (var pizzaRecipeStep in pizzaRecipe.recipeSteps){
|
||||||
|
pizzaRecipeStep.subSteps = await recipeSubStepDao.getRecipeStepSubSteps(pizzaRecipeStep.id!);
|
||||||
|
print(pizzaRecipeStep.subSteps);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return pizzaRecipes;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -11,7 +11,7 @@ abstract class IngredientDao {
|
||||||
Stream<Ingredient?> findIngredientById(int id);
|
Stream<Ingredient?> findIngredientById(int id);
|
||||||
|
|
||||||
@Query("SELECT * FROM Ingredient WHERE pizzaRecipeId = :pizzaRecipeId")
|
@Query("SELECT * FROM Ingredient WHERE pizzaRecipeId = :pizzaRecipeId")
|
||||||
Future<List<Ingredient>> getPizzaRecipeSteps(int pizzaRecipeId);
|
Future<List<Ingredient>> getPizzaRecipeIngredients(int pizzaRecipeId);
|
||||||
|
|
||||||
@insert
|
@insert
|
||||||
Future<void> insertIngredient(Ingredient ingredient);
|
Future<void> insertIngredient(Ingredient ingredient);
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:pizzaplanner/pages/AddPizzaEvent/AddPizzaEventPage.dart';
|
import 'package:pizzaplanner/pages/AddPizzaEvent/AddPizzaEventPage.dart';
|
||||||
|
import 'package:pizzaplanner/pages/AddPizzaEvent/PickPizzaRecipePage.dart';
|
||||||
import 'package:pizzaplanner/pages/PizzaEventsPage.dart';
|
import 'package:pizzaplanner/pages/PizzaEventsPage.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
@ -24,6 +25,9 @@ class RouteGenerator {
|
||||||
case "/": {
|
case "/": {
|
||||||
return MaterialPageRoute(builder: (context) => PizzaEventsPage());
|
return MaterialPageRoute(builder: (context) => PizzaEventsPage());
|
||||||
}
|
}
|
||||||
|
case "/pickRecipe": {
|
||||||
|
return MaterialPageRoute(builder: (context) => PickPizzaRecipePage());
|
||||||
|
}
|
||||||
case "/add": {
|
case "/add": {
|
||||||
return MaterialPageRoute(builder: (context) => AddPizzaEventPage());
|
return MaterialPageRoute(builder: (context) => AddPizzaEventPage());
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ class AddPizzaEventPage extends StatefulWidget {
|
||||||
class AddPizzaEventPageState extends State<AddPizzaEventPage> {
|
class AddPizzaEventPageState extends State<AddPizzaEventPage> {
|
||||||
String name = "";
|
String name = "";
|
||||||
late Future<PizzaRecipe> pizzaRecipe;
|
late Future<PizzaRecipe> pizzaRecipe;
|
||||||
final Future<List<PizzaRecipe>> pizzaRecipes = getRecipes();
|
//final Future<List<PizzaRecipe>> pizzaRecipes = getRecipes();
|
||||||
int pizzaCount = 1;
|
int pizzaCount = 1;
|
||||||
int doughBallSize = 250;
|
int doughBallSize = 250;
|
||||||
DateTime eventTime = DateTime.now();
|
DateTime eventTime = DateTime.now();
|
||||||
|
@ -61,7 +61,7 @@ class AddPizzaEventPageState extends State<AddPizzaEventPage> {
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Icon(FontAwesome5.pizza_slice),
|
Icon(FontAwesome5.pizza_slice),
|
||||||
Container(width: 25),
|
Container(width: 25),
|
||||||
Expanded(
|
/*Expanded(
|
||||||
child: FutureBuilder<List<PizzaRecipe>>(
|
child: FutureBuilder<List<PizzaRecipe>>(
|
||||||
future: pizzaRecipes,
|
future: pizzaRecipes,
|
||||||
builder: (BuildContext context, AsyncSnapshot<List<PizzaRecipe>> snapshot){
|
builder: (BuildContext context, AsyncSnapshot<List<PizzaRecipe>> snapshot){
|
||||||
|
@ -84,7 +84,7 @@ class AddPizzaEventPageState extends State<AddPizzaEventPage> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
)
|
)*/
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
Row(
|
Row(
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:pizzaplanner/entities/PizzaRecipe/PizzaRecipe.dart';
|
||||||
|
import 'package:pizzaplanner/entities/dao/AppDao.dart';
|
||||||
|
import 'package:pizzaplanner/widgets/PizzaRecipeWidget.dart';
|
||||||
|
|
||||||
|
class PickPizzaRecipePage extends StatefulWidget {
|
||||||
|
@override
|
||||||
|
PickPizzaRecipePageState createState() => PickPizzaRecipePageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class PickPizzaRecipePageState extends State<PickPizzaRecipePage> {
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
title: Text("Add Pizza2 Event"),
|
||||||
|
),
|
||||||
|
resizeToAvoidBottomInset: false,
|
||||||
|
body: Container(
|
||||||
|
padding: EdgeInsets.all(8),
|
||||||
|
child: Column(
|
||||||
|
children: <Widget>[
|
||||||
|
Expanded(
|
||||||
|
flex: 80,
|
||||||
|
child: FutureBuilder(
|
||||||
|
future: AppDao.getPizzaRecipes(),
|
||||||
|
builder: (BuildContext context, AsyncSnapshot<List<PizzaRecipe>> snapshot) {
|
||||||
|
if (snapshot.hasData && !snapshot.hasError){
|
||||||
|
return ListView(
|
||||||
|
children: snapshot.data!.map((pizzaRecipe) {
|
||||||
|
return PizzaRecipeWidget(pizzaRecipe);
|
||||||
|
}).toList(),
|
||||||
|
);
|
||||||
|
} else if (snapshot.hasError){
|
||||||
|
print(snapshot.error);
|
||||||
|
return Text("Something went wrong");
|
||||||
|
} else {
|
||||||
|
return Text("Loading Pizza Recipes");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
),
|
||||||
|
Divider(),
|
||||||
|
SizedBox(
|
||||||
|
width: double.infinity,
|
||||||
|
height: 70,
|
||||||
|
child: Container(
|
||||||
|
color: Colors.blue,
|
||||||
|
child: TextButton(
|
||||||
|
child: Text("Review", style: TextStyle(color: Colors.white)),
|
||||||
|
onPressed: () {
|
||||||
|
},
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -28,7 +28,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",
|
"/pickRecipe",
|
||||||
);
|
);
|
||||||
|
|
||||||
if (newPizzaEvent != null){
|
if (newPizzaEvent != null){
|
||||||
|
|
|
@ -5,14 +5,7 @@ import 'package:intl/intl.dart';
|
||||||
import 'package:pizzaplanner/entities/PizzaDatabase.dart';
|
import 'package:pizzaplanner/entities/PizzaDatabase.dart';
|
||||||
import 'package:pizzaplanner/entities/PizzaRecipe/PizzaRecipe.dart';
|
import 'package:pizzaplanner/entities/PizzaRecipe/PizzaRecipe.dart';
|
||||||
|
|
||||||
Future<List<PizzaRecipe>> getRecipes() async {
|
Future<List<PizzaRecipe>> loadYamlRecipesIntoDb() async {
|
||||||
final database = await getDatabase();
|
|
||||||
final pizzaRecipeDao = database.pizzaRecipeDao;
|
|
||||||
final pizzaRecipes = await pizzaRecipeDao.getAllPizzaRecipes();
|
|
||||||
if (pizzaRecipes.isNotEmpty) {
|
|
||||||
return pizzaRecipes;
|
|
||||||
}
|
|
||||||
|
|
||||||
// load recipes from yaml files in the asset directory
|
// load recipes from yaml files in the asset directory
|
||||||
final manifestContent = await rootBundle.loadString('AssetManifest.json');
|
final manifestContent = await rootBundle.loadString('AssetManifest.json');
|
||||||
final Map<String, dynamic> manifestMap = json.decode(manifestContent);
|
final Map<String, dynamic> manifestMap = json.decode(manifestContent);
|
||||||
|
@ -23,10 +16,11 @@ Future<List<PizzaRecipe>> getRecipes() async {
|
||||||
var parsedPizzaRecipe = await PizzaRecipe.fromYaml(filePath);
|
var parsedPizzaRecipe = await PizzaRecipe.fromYaml(filePath);
|
||||||
await parsedPizzaRecipe.item1.insert();
|
await parsedPizzaRecipe.item1.insert();
|
||||||
newPizzaRecipes.add(parsedPizzaRecipe.item1);
|
newPizzaRecipes.add(parsedPizzaRecipe.item1);
|
||||||
|
print(parsedPizzaRecipe.item1.name);
|
||||||
parsedPizzaRecipe.item2.forEach((ingredient) async { await ingredient.insert(); });
|
parsedPizzaRecipe.item2.forEach((ingredient) async { await ingredient.insert(); });
|
||||||
parsedPizzaRecipe.item3.forEach((recipeStep) async { await recipeStep.insert(); });
|
parsedPizzaRecipe.item3.forEach((recipeStep) async { await recipeStep.insert(); });
|
||||||
parsedPizzaRecipe.item4.forEach((recipeSubStep) async { await recipeSubStep.insert(); });
|
parsedPizzaRecipe.item4.forEach((recipeSubStep) async { await recipeSubStep.insert(); });
|
||||||
|
print(parsedPizzaRecipe.item1.description);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return newPizzaRecipes;
|
return newPizzaRecipes;
|
||||||
|
|
37
lib/widgets/PizzaRecipeWidget.dart
Normal file
37
lib/widgets/PizzaRecipeWidget.dart
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
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 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")
|
||||||
|
]
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue