refactoring

This commit is contained in:
SomnusVeritas
2023-11-13 18:51:25 +01:00
parent 64e983bc59
commit 8835c83081
6 changed files with 42 additions and 13 deletions

View File

@@ -9,21 +9,25 @@ class Ingredient {
final String title;
List<Unit> possibleUnits;
List<String> preferredBrands;
IngredientType type;
Ingredient({
required this.title,
required this.type,
this.possibleUnits = const [],
this.preferredBrands = const [],
});
factory Ingredient.fromJson(Map<String, dynamic> json) => Ingredient(
title: json['title'] as String,
type: json['ingredient_type'] as IngredientType,
possibleUnits: _unitsFromJson(json['possibleUnits']),
preferredBrands: json['preferredBrands'] as List<String>,
);
Map<String, dynamic> toJson() => {
'title': title,
'ingredient_type': type,
'possibleUnits': possibleUnits.map((e) => e.toJson()).toList(),
'preferredBrands': preferredBrands,
};
@@ -42,3 +46,15 @@ class Ingredient {
static List<Unit> _unitsFromJson(List<Map<String, dynamic>> jsonList) =>
jsonList.map((e) => Unit.fromJson(e)).toList();
}
enum IngredientType {
vegetable,
meat,
fish,
grain,
fruit,
dairy,
fatsAndOil,
spice,
other,
}