aboutsummaryrefslogtreecommitdiff
path: root/lib/models/recipe_class.dart
blob: 1787495e6594b160cfc7bd1e7fd52911bdcafbcd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import "package:isar/isar.dart";

import 'package:kulinar_app/models/data/recipe_data_class.dart';

part "recipe_class.g.dart";

@collection
class Recipe {
  Id id = Isar.autoIncrement;

  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<Recipe> list = remote ? RecipeData.remoteRecipeList : RecipeData.recipeList;

    for (Recipe recipe in list) {
      if (title == recipe.title && image == recipe.image && description == recipe.description) {
        return true;
      }
    }

    return false;
  }

  bool isDefault() {
    if (title != null) return false;
    if (image != null) return false;
    if (description != null) return false;
    if (favorite != false) return false;
    if (rating != 0) return false;

    return true;
  }

  void toggleFavorite() {
    favorite = !favorite;
  }

  void updateRating() {
    if (rating == 5) {
      rating = 0;
    } else {
      rating++;
    }
  }
}