import 'package:json_annotation/json_annotation.dart'; part 'recipe.g.dart'; /// 食材信息 @JsonSerializable() class RecipeMaterial { int id; String type; String name; String amount; RecipeMaterial({ required this.id, required this.type, required this.name, required this.amount, }); factory RecipeMaterial.fromJson(Map json) => _$RecipeMaterialFromJson(json); Map toJson() => _$RecipeMaterialToJson(this); } /// 步骤信息 @JsonSerializable() class RecipeStep { int id; int sort; String content; String imageUrl; RecipeStep({ required this.id, required this.sort, required this.content, required this.imageUrl, }); factory RecipeStep.fromJson(Map json) => _$RecipeStepFromJson(json); Map toJson() => _$RecipeStepToJson(this); } /// 评论信息 @JsonSerializable() class RecipeComment { int id; String username; String avatar; String content; String date; RecipeComment({ required this.id, required this.username, required this.avatar, required this.content, required this.date, }); factory RecipeComment.fromJson(Map json) => _$RecipeCommentFromJson(json); Map toJson() => _$RecipeCommentToJson(this); } /// 成果信息 @JsonSerializable() class FoodRecord { int? id; String name; String category; int person; String date; String imageUrl; FoodRecord({ this.id, required this.name, required this.category, required this.person, required this.date, required this.imageUrl, }); factory FoodRecord.fromJson(Map json) => _$FoodRecordFromJson(json); Map toJson() => _$FoodRecordToJson(this); static FoodRecord getEmpty() { return FoodRecord( id: 0, name: '', category: '', person: 0, date: '', imageUrl: '', ); } } @JsonSerializable() class RecipeQuery { String category; RecipeQuery({required this.category}); factory RecipeQuery.fromJson(Map json) => _$RecipeQueryFromJson(json); Map toJson() => _$RecipeQueryToJson(this); } /// 菜谱信息 @JsonSerializable() class Recipe { int id; String name; String category; double recommendRate; String remark; bool isShare; int userId; String username; String avatar; List materialList; List stepList; List recordList; List likeList; int likeCount; List favouriteList; int favouriteCount; List commentList; int commentCount; Recipe({ required this.id, required this.name, required this.category, required this.recommendRate, required this.remark, required this.isShare, required this.userId, required this.username, required this.avatar, required this.materialList, required this.stepList, required this.recordList, required this.likeList, required this.likeCount, required this.favouriteList, required this.favouriteCount, required this.commentList, required this.commentCount, }); factory Recipe.fromJson(Map json) => _$RecipeFromJson(json); Map toJson() => _$RecipeToJson(this); } @JsonSerializable() class RecipeSummary { int id; String name; String category; double recommendRate; bool isShare; List recordList; int likeCount; int favouriteCount; int commentCount; int userId; String username; String avatar; RecipeSummary({ required this.id, required this.name, required this.category, required this.recommendRate, required this.isShare, required this.userId, required this.username, required this.avatar, required this.recordList, required this.likeCount, required this.favouriteCount, required this.commentCount, }); factory RecipeSummary.fromJson(Map json) => _$RecipeSummaryFromJson(json); Map toJson() => _$RecipeSummaryToJson(this); } @JsonSerializable() class RecipeDetail { int id; String name; String category; double recommendRate; String remark; bool isShare; int userId; String username; String avatar; List materialList; List stepList; List recordList; List likeList; List favouriteList; List commentList; RecipeDetail({ required this.id, required this.name, required this.category, required this.recommendRate, required this.remark, required this.isShare, required this.userId, required this.username, required this.avatar, required this.materialList, required this.stepList, required this.recordList, required this.likeList, required this.favouriteList, required this.commentList, }); factory RecipeDetail.fromJson(Map json) => _$RecipeDetailFromJson(json); Map toJson() => _$RecipeDetailToJson(this); static RecipeDetail getEmpty() { return RecipeDetail( id: 0, name: '', category: '', recommendRate: 0, remark: '', isShare: false, userId: 0, username: '', avatar: '', materialList: [], stepList: [], recordList: [], likeList: [], favouriteList: [], commentList: [], ); } } enum ViewType { recipe, calendar, timeline }