79 lines
2.3 KiB
Dart
79 lines
2.3 KiB
Dart
class IngredientSuggestion {
|
|
final int productId;
|
|
final String productName;
|
|
final double score;
|
|
|
|
const IngredientSuggestion({
|
|
required this.productId,
|
|
required this.productName,
|
|
required this.score,
|
|
});
|
|
|
|
factory IngredientSuggestion.fromJson(Map<String, dynamic> json) =>
|
|
IngredientSuggestion(
|
|
productId: (json['productId'] as num).toInt(),
|
|
productName: json['productName'] as String? ?? '',
|
|
score: (json['score'] as num).toDouble(),
|
|
);
|
|
}
|
|
|
|
class ParsedIngredient {
|
|
final String rawName;
|
|
final double quantity;
|
|
final String unit;
|
|
final String? note;
|
|
final List<IngredientSuggestion> suggestions;
|
|
final List<String> alternatives;
|
|
|
|
const ParsedIngredient({
|
|
required this.rawName,
|
|
required this.quantity,
|
|
required this.unit,
|
|
this.note,
|
|
required this.suggestions,
|
|
this.alternatives = const [],
|
|
});
|
|
|
|
factory ParsedIngredient.fromJson(Map<String, dynamic> json) {
|
|
final rawSuggestions = json['suggestions'] as List<dynamic>? ?? [];
|
|
return ParsedIngredient(
|
|
rawName: json['rawName'] as String? ?? '',
|
|
quantity: (json['quantity'] as num? ?? 0).toDouble(),
|
|
unit: json['unit'] as String? ?? '',
|
|
note: json['note'] as String?,
|
|
suggestions: rawSuggestions
|
|
.map((s) => IngredientSuggestion.fromJson(s as Map<String, dynamic>))
|
|
.toList(),
|
|
alternatives: (json['alternatives'] as List<dynamic>? ?? [])
|
|
.map((a) => a as String)
|
|
.toList(),
|
|
);
|
|
}
|
|
}
|
|
|
|
class ParsedRecipe {
|
|
final String name;
|
|
final String? description;
|
|
final String? instructions;
|
|
final List<ParsedIngredient> ingredients;
|
|
|
|
const ParsedRecipe({
|
|
required this.name,
|
|
this.description,
|
|
this.instructions,
|
|
required this.ingredients,
|
|
});
|
|
|
|
factory ParsedRecipe.fromJson(Map<String, dynamic> json) {
|
|
final rawIngredients = json['ingredients'] as List<dynamic>? ?? [];
|
|
return ParsedRecipe(
|
|
name: json['name'] as String? ?? '',
|
|
description: json['description'] as String?,
|
|
instructions: json['instructions'] as String?,
|
|
ingredients: rawIngredients
|
|
.map((i) => ParsedIngredient.fromJson(i as Map<String, dynamic>))
|
|
.toList(),
|
|
);
|
|
}
|
|
}
|