import 'dart:convert'; import 'package:kulinar_app/models/data/recipe_data_class.dart'; class Recipe { String? title; String? image; String? description; bool favorite; int rating; Recipe({this.title, this.image, this.description, this.favorite = false, this.rating = 0}); bool isListed({bool remote = false}) { List _list = remote ? RecipeData.remoteRecipeList : RecipeData.recipeList; for (Recipe recipe in _list) { if (this.title == recipe.title && this.image == recipe.image && this.description == recipe.description) { return true; } } return false; } bool isDefault() { if (this.title != null) return false; if (this.image != null) return false; if (this.description != null) return false; if (this.favorite != false) return false; if (this.rating != 0) return false; return true; } static Recipe fromJson(String string) { final json = jsonDecode(string); return Recipe(title: json["title"], image: json["image"], description: json["description"]); } String toJsonString() { Map map = { "title": this.title ?? "", "image": this.image ?? "", "description": this.description ?? "", }; return jsonEncode(map); } void toggleFavorite() { this.favorite = !this.favorite; } void updateRating() { if (this.rating == 5) { this.rating = 0; } else { this.rating++; } } }