khoirul_romadhon/easycook_mobile/lib/models/home.dart
2024-12-31 09:26:36 +07:00

86 lines
2.0 KiB
Dart

import 'dart:convert';
class RecipeResponse {
RecipeResponse({
required this.data,
});
List<Recipe> data;
factory RecipeResponse.fromJson(Map<String, dynamic> json) => RecipeResponse(
data: List<Recipe>.from(json["data"].map((x) => Recipe.fromJson(x))),
);
Map<String, dynamic> toJson() => {
"data": List<dynamic>.from(data.map((x) => x.toJson())),
};
}
class Recipe {
int id;
String title;
String imageUrl;
String difficulty;
String sourceUrl;
int calories;
int completenessPercentage;
bool isFavorited;
Rating rating;
Recipe({
required this.id,
required this.title,
required this.imageUrl,
required this.difficulty,
required this.sourceUrl,
required this.calories,
required this.completenessPercentage,
required this.isFavorited,
required this.rating,
});
factory Recipe.fromJson(Map<String, dynamic> json) => Recipe(
id: json["id"],
title: json["title"],
imageUrl: json["image_url"],
difficulty: json["difficulty"],
sourceUrl: json["source_url"],
calories: json["calories"],
completenessPercentage: json["completeness_percentage"],
isFavorited: json["is_favorited"],
rating: Rating.fromJson(json["rating"]),
);
Map<String, dynamic> toJson() => {
"id": id,
"title": title,
"image_url": imageUrl,
"difficulty": difficulty,
"source_url": sourceUrl,
"calories": calories,
"completeness_percentage": completenessPercentage,
"is_favorited": isFavorited,
"rating": rating.toJson(),
};
}
class Rating {
double score;
int amount;
Rating({
required this.score,
required this.amount,
});
factory Rating.fromJson(Map<String, dynamic> json) => Rating(
score: json["score"],
amount: json["amount"],
);
Map<String, dynamic> toJson() => {
"score": score,
"amount": amount,
};
}