feat: add recipe creation, editing, and detail screens; enhance recipe model with instructions and ingredients
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
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;
|
||||
|
||||
const ParsedIngredient({
|
||||
required this.rawName,
|
||||
required this.quantity,
|
||||
required this.unit,
|
||||
this.note,
|
||||
required this.suggestions,
|
||||
});
|
||||
|
||||
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(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
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(),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user