summaryrefslogtreecommitdiff
path: root/lib/models/popular_detail.dart
blob: 8b158acdf96a3d536bafc5d4539ca97688ab9ffb (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import 'package:pmsna1/models/popular_credit.dart';
import 'package:pmsna1/models/popular_video.dart';

class Genre {
  int? id;
  String? name;
}

class PopularDetail {
  bool? adult;
  String? backdropPath;
  int? budget;
  List<Genre>? genres;
  String? homepage;
  int? id;
  String? originalLanguage;
  String? overview;
  double? popularity;
  String? posterPath;
  String? releaseDate;
  int? revenue;
  int? runtime;
  String? tagline;
  String? title;
  bool? video;
  double? voteAverage;
  double? voteCount;
  List<PopularVideo> videos;
  List<PopularCredit> credits;

  bool hasFavorite = false;

  PopularDetail({
    this.adult,
    this.backdropPath,
    this.budget,
    this.genres,
    this.homepage,
    this.id,
    this.originalLanguage,
    this.overview,
    this.popularity,
    this.posterPath,
    this.releaseDate,
    this.revenue,
    this.runtime,
    this.tagline,
    this.title,
    this.video,
    this.voteAverage,
    this.voteCount,
    this.videos = const [],
    this.credits = const [],
  });

  factory PopularDetail.fromMap(Map<String, dynamic> map) {
    return PopularDetail(
      adult: map['adult'],
      backdropPath: map['backdrop_path'],
      id: map['id'],
      originalLanguage: map['original_language'],
      overview: map['overview'],
      popularity: map['popularity'],
      posterPath: map['posterPath'],
      releaseDate: map['releaseDate'],
      revenue: map['revenue'],
      runtime: map['runtime'],
      tagline: map['tagline'],
      title: map['title'],
      video: map['video'],
      voteAverage: (map['vote_average'] is int)
          ? (map['vote_average'] as int).toDouble()
          : map['vote_average'],
      voteCount: map['voteCount'],
      videos: (map['videos']['results'] as List<dynamic>)
          .map((v) => PopularVideo.fromMap(v))
          .toList(),
      credits: (map['credits']['cast'] as List<dynamic>)
          .map((c) => PopularCredit.fromMap(c))
          .toList(),
    );
  }
}