refactoring
This commit is contained in:
@@ -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,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user