in between commit adding Floor ORM
This commit is contained in:
parent
bdd09a9a3a
commit
810e77894e
12 changed files with 162 additions and 7 deletions
35
lib/entities/PizzaDatabase.dart
Normal file
35
lib/entities/PizzaDatabase.dart
Normal file
|
@ -0,0 +1,35 @@
|
|||
import 'package:floor/floor.dart';
|
||||
import 'package:pizzaplanner/entities/PizzaEvent.dart';
|
||||
import 'package:pizzaplanner/entities/PizzaRecipe/Ingredient.dart';
|
||||
import 'package:pizzaplanner/entities/PizzaRecipe/PizzaRecipe.dart';
|
||||
import 'package:pizzaplanner/entities/PizzaRecipe/RecipeStep.dart';
|
||||
import 'package:pizzaplanner/entities/PizzaRecipe/RecipeSubStep.dart';
|
||||
import 'package:pizzaplanner/entities/dao/IngridientDao.dart';
|
||||
import 'package:pizzaplanner/entities/dao/PizzaEventDoa.dart';
|
||||
import 'package:pizzaplanner/entities/dao/PizzaRecipeDao.dart';
|
||||
import 'package:pizzaplanner/entities/dao/RecipeStepDao.dart';
|
||||
import 'package:pizzaplanner/entities/dao/RecipeSubStepDao.dart';
|
||||
|
||||
part 'PizzaDatabase.g.dart';
|
||||
|
||||
@TypeConverters([DateTimeConverter])
|
||||
@Database(version: 1, entities: [PizzaEvent, PizzaRecipe, RecipeStep, RecipeSubStep, Ingredient])
|
||||
abstract class PizzaDatabase extends FloorDatabase {
|
||||
PizzaEventDoa get pizzaEventDoa;
|
||||
PizzaRecipeDao get pizzaRecipeDao;
|
||||
RecipeStepDao get recipeStepDao;
|
||||
RecipeSubStepDao get recipeSubStepDao;
|
||||
IngredientDao get ingredientDao;
|
||||
}
|
||||
|
||||
class DateTimeConverter extends TypeConverter<DateTime, int> {
|
||||
@override
|
||||
DateTime decode(int databaseValue) {
|
||||
return DateTime.fromMillisecondsSinceEpoch(databaseValue);
|
||||
}
|
||||
|
||||
@override
|
||||
int encode(DateTime value) {
|
||||
return value.millisecondsSinceEpoch;
|
||||
}
|
||||
}
|
|
@ -1,8 +1,15 @@
|
|||
|
||||
import 'package:pizzaplanner/entities/PizzaRecipe/PizzaRecipe.dart';
|
||||
|
||||
import 'package:floor/floor.dart';
|
||||
|
||||
@entity
|
||||
class PizzaEvent {
|
||||
@PrimaryKey(autoGenerate: true)
|
||||
final int? id;
|
||||
|
||||
final String name;
|
||||
@ignore
|
||||
final PizzaRecipe recipe;
|
||||
final int pizzaCount;
|
||||
final int doughBallSize;
|
||||
|
@ -13,6 +20,7 @@ class PizzaEvent {
|
|||
this.recipe,
|
||||
this.pizzaCount,
|
||||
this.doughBallSize,
|
||||
this.dateTime
|
||||
this.dateTime,
|
||||
{this.id,}
|
||||
);
|
||||
}
|
|
@ -1,13 +1,19 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:floor/floor.dart';
|
||||
|
||||
import 'package:pizzaplanner/util.dart';
|
||||
|
||||
@entity
|
||||
class Ingredient {
|
||||
@PrimaryKey(autoGenerate: true)
|
||||
final int? id;
|
||||
|
||||
final String name;
|
||||
final String unit;
|
||||
final double value;
|
||||
|
||||
Ingredient(this.name, this.unit, this.value);
|
||||
Ingredient(this.name, this.unit, this.value, {this.id});
|
||||
|
||||
TableRow getIngredientTableRow(int pizzaCount, int doughBallSize){
|
||||
return TableRow(
|
||||
|
|
|
@ -1,21 +1,28 @@
|
|||
import 'package:floor/floor.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:pizzaplanner/entities/PizzaDatabase.dart';
|
||||
import 'package:pizzaplanner/util.dart';
|
||||
import 'package:pizzaplanner/entities/PizzaRecipe/Ingredient.dart';
|
||||
|
||||
import 'package:pizzaplanner/entities/PizzaRecipe/Ingredients.dart';
|
||||
import 'package:pizzaplanner/entities/PizzaRecipe/RecipeStep.dart';
|
||||
import 'package:pizzaplanner/entities/PizzaRecipe/RecipeSubStep.dart';
|
||||
import 'package:pizzaplanner/util.dart';
|
||||
import 'package:yaml/yaml.dart';
|
||||
|
||||
@entity
|
||||
class PizzaRecipe {
|
||||
@PrimaryKey(autoGenerate: true)
|
||||
final int? id;
|
||||
|
||||
final String name;
|
||||
final String description;
|
||||
|
||||
@ignore
|
||||
final List<Ingredient> ingredients;
|
||||
|
||||
@ignore
|
||||
final List<RecipeStep> recipeSteps;
|
||||
|
||||
PizzaRecipe(this.name, this.description, this.ingredients, this.recipeSteps);
|
||||
PizzaRecipe(this.name, this.description, this.ingredients, this.recipeSteps, {this.id});
|
||||
|
||||
Table getIngredientsTable(int pizzaCount, int doughBallSize) {
|
||||
return Table(
|
||||
|
@ -89,6 +96,17 @@ class PizzaRecipe {
|
|||
);
|
||||
});
|
||||
|
||||
final database = await $FloorPizzaDatabase.databaseBuilder("app.db").build();
|
||||
|
||||
final recipeDao = database.pizzaRecipeDao;
|
||||
await recipeDao.insertPizzaRecipe(PizzaRecipe(
|
||||
name,
|
||||
description,
|
||||
newIngredients,
|
||||
newRecipeSteps
|
||||
));
|
||||
|
||||
|
||||
return PizzaRecipe(
|
||||
name,
|
||||
description,
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
import 'package:floor/floor.dart';
|
||||
import 'package:pizzaplanner/entities/PizzaRecipe/RecipeSubStep.dart';
|
||||
|
||||
@entity
|
||||
class RecipeStep {
|
||||
@PrimaryKey(autoGenerate: true)
|
||||
final int? id;
|
||||
final String name;
|
||||
final String waitDescription;
|
||||
final String waitUnit;
|
||||
|
@ -8,9 +12,11 @@ class RecipeStep {
|
|||
final int waitMax;
|
||||
late int waitValue;
|
||||
final String description;
|
||||
|
||||
@ignore
|
||||
final List<RecipeSubStep> subSteps;
|
||||
|
||||
RecipeStep(this.name, this.description, this.waitDescription, this.waitUnit, this.waitMin, this.waitMax, this.subSteps) {
|
||||
RecipeStep(this.name, this.description, this.waitDescription, this.waitUnit, this.waitMin, this.waitMax, this.subSteps, {this.id}) {
|
||||
waitValue = waitMin;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
import 'package:floor/floor.dart';
|
||||
|
||||
@entity
|
||||
class RecipeSubStep {
|
||||
@PrimaryKey(autoGenerate: true)
|
||||
final int? id;
|
||||
|
||||
final String name;
|
||||
final String description;
|
||||
|
||||
RecipeSubStep(this.name, this.description);
|
||||
RecipeSubStep(this.name, this.description, {this.id});
|
||||
}
|
15
lib/entities/dao/IngridientDao.dart
Normal file
15
lib/entities/dao/IngridientDao.dart
Normal file
|
@ -0,0 +1,15 @@
|
|||
import 'package:floor/floor.dart';
|
||||
import 'package:pizzaplanner/entities/PizzaRecipe/Ingredient.dart';
|
||||
import 'package:pizzaplanner/entities/PizzaRecipe/PizzaRecipe.dart';
|
||||
|
||||
@dao
|
||||
abstract class IngredientDao {
|
||||
@Query("SELECT * FROM Ingredient")
|
||||
Future<List<Ingredient>> getAllIngredients();
|
||||
|
||||
@Query("SELECT * FROM Ingredient WHERE id = :id")
|
||||
Stream<Ingredient?> findIngredientById(int id);
|
||||
|
||||
@insert
|
||||
Future<void> insertIngredient(Ingredient ingredient);
|
||||
}
|
14
lib/entities/dao/PizzaEventDoa.dart
Normal file
14
lib/entities/dao/PizzaEventDoa.dart
Normal file
|
@ -0,0 +1,14 @@
|
|||
import 'package:floor/floor.dart';
|
||||
import 'package:pizzaplanner/entities/PizzaEvent.dart';
|
||||
|
||||
@dao
|
||||
abstract class PizzaEventDoa {
|
||||
@Query("SELECT * FROM PizzaEvent")
|
||||
Future<List<PizzaEvent>> getAllPizzaEvents();
|
||||
|
||||
@Query("SELECT * FROM PizzaEvent WHERE id = :id")
|
||||
Stream<PizzaEvent?> findPizzaEventById(int id);
|
||||
|
||||
@insert
|
||||
Future<void> insertPizzaEvent(PizzaEvent pizzaEvent);
|
||||
}
|
14
lib/entities/dao/PizzaRecipeDao.dart
Normal file
14
lib/entities/dao/PizzaRecipeDao.dart
Normal file
|
@ -0,0 +1,14 @@
|
|||
import 'package:floor/floor.dart';
|
||||
import 'package:pizzaplanner/entities/PizzaRecipe/PizzaRecipe.dart';
|
||||
|
||||
@dao
|
||||
abstract class PizzaRecipeDao {
|
||||
@Query("SELECT * FROM PizzaRecipe")
|
||||
Future<List<PizzaRecipe>> getAllPizzaRecipes();
|
||||
|
||||
@Query("SELECT * FROM PizzaRecipe WHERE id = :id")
|
||||
Stream<PizzaRecipe?> findPizzaRecipeById(int id);
|
||||
|
||||
@insert
|
||||
Future<void> insertPizzaRecipe(PizzaRecipe pizzaRecipe);
|
||||
}
|
14
lib/entities/dao/RecipeStepDao.dart
Normal file
14
lib/entities/dao/RecipeStepDao.dart
Normal file
|
@ -0,0 +1,14 @@
|
|||
import 'package:floor/floor.dart';
|
||||
import 'package:pizzaplanner/entities/PizzaRecipe/RecipeStep.dart';
|
||||
|
||||
@dao
|
||||
abstract class RecipeStepDao {
|
||||
@Query("SELECT * FROM RecipeStep")
|
||||
Future<List<RecipeStep>> getAllRecipeSteps();
|
||||
|
||||
@Query("SELECT * FROM RecipeStep WHERE id = :id")
|
||||
Stream<RecipeStep?> findRecipeStepById(int id);
|
||||
|
||||
@insert
|
||||
Future<void> insertRecipeStep(RecipeStep recipeStep);
|
||||
}
|
14
lib/entities/dao/RecipeSubStepDao.dart
Normal file
14
lib/entities/dao/RecipeSubStepDao.dart
Normal file
|
@ -0,0 +1,14 @@
|
|||
import 'package:floor/floor.dart';
|
||||
import 'package:pizzaplanner/entities/PizzaRecipe/RecipeSubStep.dart';
|
||||
|
||||
@dao
|
||||
abstract class RecipeSubStepDao {
|
||||
@Query("SELECT * FROM RecipeSubStep")
|
||||
Future<List<RecipeSubStep>> getAllRecipeSubSteps();
|
||||
|
||||
@Query("SELECT * FROM RecipeSubStep WHERE id = :id")
|
||||
Stream<RecipeSubStep?> findRecipeSubStepById(int id);
|
||||
|
||||
@insert
|
||||
Future<void> insertRecipeSubStep(RecipeSubStep recipeSubStep);
|
||||
}
|
|
@ -35,10 +35,15 @@ dependencies:
|
|||
ref: "df4ed6fc2e24725604e90f79aedb98a7af7fb04d"
|
||||
yaml: ^3.1.0
|
||||
|
||||
floor: ^1.1.0
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
|
||||
floor_generator: ^1.1.0
|
||||
build_runner: ^2.0.0
|
||||
|
||||
# For information on the generic Dart part of this file, see the
|
||||
# following page: https://dart.dev/tools/pub/pubspec
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue