import 'dart:convert'; class RecipeDetail { int id; String title; String imageUrl; int time; int servings; String difficulty; String sourceUrl; Rating rating; bool isFavorited; List ingredients; List instructions; List ownedIngredients; List notOwnedIngredients; RecipeDetail({ required this.id, required this.title, required this.imageUrl, required this.time, required this.servings, required this.difficulty, required this.sourceUrl, required this.rating, required this.isFavorited, required this.ingredients, required this.instructions, required this.ownedIngredients, required this.notOwnedIngredients, }); factory RecipeDetail.fromJson(Map json) => RecipeDetail( id: json["id"], title: json["title"], imageUrl: json["image_url"], time: json["time"], servings: json["servings"], difficulty: json["difficulty"], sourceUrl: json["source_url"], rating: Rating.fromJson(json["rating"]), isFavorited: json["is_favorited"], ingredients: List.from( json["ingredients"].map((x) => Ingredient.fromJson(x))), instructions: List.from(json["instructions"].map((x) => x)), ownedIngredients: List.from( json["owned_ingredients"].map((x) => Ingredient.fromJson(x))), notOwnedIngredients: List.from( json["not_owned_ingredients"].map((x) => Ingredient.fromJson(x))), ); Map toJson() => { "id": id, "title": title, "image_url": imageUrl, "time": time, "servings": servings, "difficulty": difficulty, "source_url": sourceUrl, "rating": rating.toJson(), "is_favorited": isFavorited, "ingredients": List.from(ingredients.map((x) => x.toJson())), "instructions": List.from(instructions.map((x) => x)), "owned_ingredients": List.from(ownedIngredients.map((x) => x.toJson())), "not_owned_ingredients": List.from(notOwnedIngredients.map((x) => x.toJson())), }; } class Ingredient { int id; String name; double amount; String state; int recipe; String unit; Ingredient({ required this.id, required this.name, required this.amount, required this.state, required this.recipe, required this.unit, }); factory Ingredient.fromJson(Map json) => Ingredient( id: json["id"], name: json["name"], amount: json["amount"], state: json["state"], recipe: json["recipe"], unit: json["unit"] ?? "", ); Map toJson() => { "id": id, "name": name, "amount": amount, "state": state, "recipe": recipe, "unit": unit, }; } class Rating { double score; int amount; Rating({ required this.score, required this.amount, }); factory Rating.fromJson(Map json) => Rating( score: json["score"], amount: json["amount"], ); Map toJson() => { "score": score, "amount": amount, }; } class EnumValues { Map map; late Map reverseMap; EnumValues(this.map); Map get reverse { reverseMap = map.map((k, v) => MapEntry(v, k)); return reverseMap; } }