39 lines
1.1 KiB
Dart
39 lines
1.1 KiB
Dart
class RecipeIngredient {
|
|
final int id;
|
|
final int? productId;
|
|
final String? productName;
|
|
final String rawName;
|
|
final String? rawLine;
|
|
final double quantity;
|
|
final String unit;
|
|
final String? note;
|
|
|
|
const RecipeIngredient({
|
|
required this.id,
|
|
this.productId,
|
|
this.productName,
|
|
required this.rawName,
|
|
this.rawLine,
|
|
required this.quantity,
|
|
required this.unit,
|
|
this.note,
|
|
});
|
|
|
|
factory RecipeIngredient.fromJson(Map<String, dynamic> json) {
|
|
final product = json['product'] as Map<String, dynamic>?;
|
|
final rawQty = json['quantity'];
|
|
return RecipeIngredient(
|
|
id: (json['id'] as num).toInt(),
|
|
productId: (json['productId'] as num?)?.toInt(),
|
|
productName: product?['canonicalName'] as String? ?? product?['name'] as String?,
|
|
rawName: json['rawName'] as String? ?? '',
|
|
rawLine: json['rawLine'] as String?,
|
|
quantity: rawQty is num
|
|
? rawQty.toDouble()
|
|
: double.tryParse(rawQty?.toString() ?? '') ?? 0,
|
|
unit: json['unit'] as String? ?? '',
|
|
note: json['note'] as String?,
|
|
);
|
|
}
|
|
}
|