barely working example with Isar
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
import 'package:isar/isar.dart';
|
||||
|
||||
part 'cooking_step.g.dart';
|
||||
|
||||
@embedded
|
||||
class CookingStep {
|
||||
final String title;
|
||||
final String description;
|
||||
|
||||
@@ -21,4 +21,4 @@ class DifficultyUtil {
|
||||
}
|
||||
|
||||
// Only use camelCase or UpperCamelCase for names
|
||||
enum Difficulty { veryEasy, easy, intermediate, hard, veryHard }
|
||||
enum Difficulty { notSelected, veryEasy, easy, intermediate, hard, veryHard }
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
import 'package:isar/isar.dart';
|
||||
|
||||
import 'unit.dart';
|
||||
|
||||
part 'ingredient.g.dart';
|
||||
|
||||
@embedded
|
||||
class Ingredient {
|
||||
final String title;
|
||||
List<Unit> possibleUnits;
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
import 'package:isar/isar.dart';
|
||||
|
||||
import 'ingredient.dart';
|
||||
import 'unit.dart';
|
||||
|
||||
part 'ingredient_list_entry.g.dart';
|
||||
|
||||
@embedded
|
||||
class IngredientListEntry {
|
||||
final Ingredient ingredient;
|
||||
final int amount;
|
||||
|
||||
@@ -1,35 +1,46 @@
|
||||
import 'package:isar/isar.dart';
|
||||
import 'package:rezepte/models/ingredient.dart';
|
||||
import 'package:rezepte/models/unit.dart';
|
||||
|
||||
import 'difficulty.dart';
|
||||
import 'cooking_step.dart';
|
||||
import 'ingredient_list_entry.dart';
|
||||
|
||||
part 'recipe.g.dart';
|
||||
|
||||
@collection
|
||||
class Recipe {
|
||||
final int id;
|
||||
String title;
|
||||
String description;
|
||||
Difficulty? difficulty;
|
||||
Difficulty difficulty;
|
||||
List<IngredientListEntry> ingredients = [];
|
||||
List<CookingStep> steps = [];
|
||||
|
||||
Recipe({
|
||||
required this.id,
|
||||
required this.title,
|
||||
this.description = '',
|
||||
this.difficulty,
|
||||
this.difficulty = Difficulty.notSelected,
|
||||
});
|
||||
|
||||
factory Recipe.fromJson(json) => Recipe(
|
||||
id: json['id'] as int,
|
||||
title: json['title'] as String,
|
||||
description: json['description'] as String,
|
||||
// difficulty: json['difficulty'] as Difficulty?,
|
||||
);
|
||||
// ..ingredients = _ingredientsFromMap(
|
||||
// json['ingredients'] as List<Map<String, dynamic>>)
|
||||
// ..steps = _stepsFromMap(json['steps']);
|
||||
difficulty: json['difficulty'] as Difficulty,
|
||||
)
|
||||
..ingredients = _ingredientsFromMap(
|
||||
json['ingredients'] as List<Map<String, dynamic>>)
|
||||
..steps = _stepsFromMap(json['steps']);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'id': id,
|
||||
'title': title,
|
||||
'description': description,
|
||||
// 'difficulty': difficulty,
|
||||
// 'ingredients': ingredients.map((e) => e.toJson()).toList(),
|
||||
// 'steps': steps.map((e) => e.toJson()).toList(),
|
||||
'difficulty': difficulty,
|
||||
'ingredients': ingredients.map((e) => e.toJson()).toList(),
|
||||
'steps': steps.map((e) => e.toJson()).toList(),
|
||||
};
|
||||
|
||||
void addIngredient(IngredientListEntry ingredient) =>
|
||||
@@ -52,7 +63,7 @@ class Recipe {
|
||||
bool get isEmpty {
|
||||
return title.isEmpty &&
|
||||
description.isEmpty &&
|
||||
difficulty == null &&
|
||||
difficulty == Difficulty.notSelected &&
|
||||
ingredients.isEmpty &&
|
||||
steps.isEmpty;
|
||||
}
|
||||
@@ -64,7 +75,7 @@ class Recipe {
|
||||
void clear() {
|
||||
title = '';
|
||||
description = '';
|
||||
difficulty = null;
|
||||
difficulty = Difficulty.notSelected;
|
||||
ingredients.clear();
|
||||
steps.clear();
|
||||
}
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
import 'package:isar/isar.dart';
|
||||
|
||||
part 'unit.g.dart';
|
||||
|
||||
@embedded
|
||||
class Unit {
|
||||
final String name;
|
||||
final UnitType type;
|
||||
|
||||
Reference in New Issue
Block a user