summaryrefslogtreecommitdiff
path: root/lib/models/popular.dart
blob: a1c136bbf0338abc3a898edc8203f55d726d5f2b (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
class Popular {
  String? backdropPath;
  int? id;
  String? originalLanguage;
  String? originalTitle;
  String? overview;
  double? popularity;
  String? posterPath;
  String? releaseDate;
  String? title;
  double? voteAverage;
  int? voteCount;

  bool hasFavorite = false;

  Popular({
    this.backdropPath,
    this.id,
    this.originalLanguage,
    this.originalTitle,
    this.overview,
    this.popularity,
    this.posterPath,
    this.releaseDate,
    this.title,
    this.voteAverage,
    this.voteCount,
  });

  Map<String, dynamic> toDb() {
    return {
      "id": id,
      "title": title,
      "posterPath": posterPath,
      "backdropPath": backdropPath,
      "overview": overview,
    };
  }

  factory Popular.fromDb(Map<String, dynamic> map) {
    return Popular(
      id: map['id'],
      title: map['title'],
      posterPath: map['posterPath'],
      backdropPath: map['backdropPath'],
      overview: map['overview'],
    );
  }

  factory Popular.fromMap(Map<String, dynamic> map) {
    return Popular(
      backdropPath: map['backdrop_path'],
      id: map['id'],
      originalLanguage: map['original_language'],
      originalTitle: map['original_title'],
      overview: map['overview'],
      popularity: map['popularity'],
      posterPath: map['poster_path'],
      releaseDate: map['release_date'],
      title: map['title'],
      voteAverage: (map['vote_average'] is int)
          ? (map['vote_average'] as int).toDouble()
          : map['vote_average'],
      voteCount: map['vote_count'],
    );
  }
}