Files
rezepte/lib/models/ingredient.dart
2023-11-06 18:19:52 +01:00

40 lines
999 B
Dart

import 'unit.dart';
class Ingredient {
final String title;
List<Unit> possibleUnits;
List<String> preferredBrands;
Ingredient({
required this.title,
this.possibleUnits = const [],
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;
return title == i.title;
}
@override
int get hashCode {
return Object.hash(title, null);
}
static List<Unit> _unitsFromJson(List<Map<String, dynamic>> jsonList) =>
jsonList.map((e) => Unit.fromJson(e)).toList();
}