feat: add recipe creation, editing, and detail screens; enhance recipe model with instructions and ingredients

This commit is contained in:
Nils-Johan Gynther
2026-04-22 07:53:25 +02:00
parent 2ea18503ef
commit ed4e18dc31
10 changed files with 1017 additions and 44 deletions
@@ -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(),
);
}
}