barely functional database with hive
This commit is contained in:
@@ -3,4 +3,14 @@ class CookingStep {
|
||||
final String description;
|
||||
|
||||
CookingStep({required this.title, this.description = ''});
|
||||
|
||||
factory CookingStep.fromJson(Map<String, dynamic> json) => CookingStep(
|
||||
title: json['title'] as String,
|
||||
description: json['description'] as String,
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'title': title,
|
||||
'description': description,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -11,6 +11,18 @@ class Ingredient {
|
||||
this.preferredBrands = const [],
|
||||
});
|
||||
|
||||
factory Ingredient.fromJson(Map<String, dynamic> json) => Ingredient(
|
||||
title: json['title'] as String,
|
||||
possibleUnits: _unitsFromJson(json['possibleUnits']),
|
||||
preferredBrands: json['preferredBrands'] as List<String>,
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'title': title,
|
||||
'possibleUnits': possibleUnits.map((e) => e.toJson()).toList(),
|
||||
'preferredBrands': preferredBrands,
|
||||
};
|
||||
|
||||
@override
|
||||
bool operator ==(other) {
|
||||
Ingredient i = other as Ingredient;
|
||||
@@ -21,4 +33,7 @@ class Ingredient {
|
||||
int get hashCode {
|
||||
return Object.hash(title, null);
|
||||
}
|
||||
|
||||
static List<Unit> _unitsFromJson(List<Map<String, dynamic>> jsonList) =>
|
||||
jsonList.map((e) => Unit.fromJson(e)).toList();
|
||||
}
|
||||
|
||||
@@ -9,6 +9,21 @@ class IngredientListEntry {
|
||||
|
||||
IngredientListEntry(this.ingredient, this.amount, this.unit, this.optional);
|
||||
|
||||
factory IngredientListEntry.fromJson(Map<String, dynamic> json) =>
|
||||
IngredientListEntry(
|
||||
Ingredient.fromJson(json['ingredient']),
|
||||
json['amount'] as int,
|
||||
Unit.fromJson(json['unit']),
|
||||
json['optional'] as bool,
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'ingredient': ingredient.toJson(),
|
||||
'amount': amount,
|
||||
'unit': unit.toJson(),
|
||||
'optional': optional,
|
||||
};
|
||||
|
||||
@override
|
||||
operator ==(Object other) {
|
||||
final i = other as IngredientListEntry;
|
||||
|
||||
@@ -6,8 +6,8 @@ class Recipe {
|
||||
String title;
|
||||
String description;
|
||||
Difficulty? difficulty;
|
||||
final List<IngredientListEntry> ingredients = [];
|
||||
final List<CookingStep> steps = [];
|
||||
List<IngredientListEntry> ingredients = [];
|
||||
List<CookingStep> steps = [];
|
||||
|
||||
Recipe({
|
||||
required this.title,
|
||||
@@ -15,6 +15,23 @@ class Recipe {
|
||||
this.difficulty,
|
||||
});
|
||||
|
||||
factory Recipe.fromJson(json) => Recipe(
|
||||
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']);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'title': title,
|
||||
'description': description,
|
||||
// 'difficulty': difficulty,
|
||||
// 'ingredients': ingredients.map((e) => e.toJson()).toList(),
|
||||
// 'steps': steps.map((e) => e.toJson()).toList(),
|
||||
};
|
||||
|
||||
void addIngredient(IngredientListEntry ingredient) =>
|
||||
ingredients.add(ingredient);
|
||||
|
||||
@@ -51,4 +68,11 @@ class Recipe {
|
||||
ingredients.clear();
|
||||
steps.clear();
|
||||
}
|
||||
|
||||
static List<IngredientListEntry> _ingredientsFromMap(
|
||||
List<Map<String, dynamic>> jsonList) =>
|
||||
jsonList.map((e) => IngredientListEntry.fromJson(e)).toList();
|
||||
|
||||
static List<CookingStep> _stepsFromMap(List<Map<String, dynamic>> jsonList) =>
|
||||
jsonList.map((e) => CookingStep.fromJson(e)).toList();
|
||||
}
|
||||
|
||||
@@ -4,6 +4,18 @@ class Unit {
|
||||
final System system;
|
||||
|
||||
Unit(this.name, this.type, {this.system = System.metric});
|
||||
|
||||
factory Unit.fromJson(Map<String, dynamic> json) => Unit(
|
||||
json['name'] as String,
|
||||
json['type'] as UnitType,
|
||||
system: json['system'] as System,
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'name': name,
|
||||
'type': type,
|
||||
'system': system,
|
||||
};
|
||||
}
|
||||
|
||||
enum System { metric, imperial, neutral }
|
||||
|
||||
Reference in New Issue
Block a user