feat: add recipe creation, editing, and detail screens; enhance recipe model with instructions and ingredients
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
import 'recipe_ingredient.dart';
|
||||
|
||||
class Recipe {
|
||||
final int id;
|
||||
final String title;
|
||||
final String? description;
|
||||
final String? imageUrl;
|
||||
final int? servings;
|
||||
final String? instructions;
|
||||
final List<RecipeIngredient> ingredients;
|
||||
|
||||
const Recipe({
|
||||
required this.id,
|
||||
@@ -11,6 +15,8 @@ class Recipe {
|
||||
this.description,
|
||||
this.imageUrl,
|
||||
this.servings,
|
||||
this.instructions,
|
||||
this.ingredients = const [],
|
||||
});
|
||||
|
||||
factory Recipe.fromJson(Map<String, dynamic> json) {
|
||||
@@ -19,6 +25,7 @@ class Recipe {
|
||||
final dynamic rawDescription = json['description'];
|
||||
final dynamic rawImageUrl = json['imageUrl'];
|
||||
final dynamic rawServings = json['servings'];
|
||||
final rawIngredients = json['ingredients'] as List<dynamic>? ?? [];
|
||||
|
||||
return Recipe(
|
||||
id: rawId is num ? rawId.toInt() : int.parse(rawId.toString()),
|
||||
@@ -30,6 +37,10 @@ class Recipe {
|
||||
: (rawServings is num
|
||||
? rawServings.toInt()
|
||||
: int.tryParse(rawServings.toString())),
|
||||
instructions: json['instructions'] as String?,
|
||||
ingredients: rawIngredients
|
||||
.map((i) => RecipeIngredient.fromJson(i as Map<String, dynamic>))
|
||||
.toList(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user