1+ import 'package:json_annotation/json_annotation.dart' ;
2+
3+ part 'movie_responses.g.dart' ;
4+
5+ @JsonSerializable ()
6+ class MoviesResponse {
7+ final int page;
8+ final List <Movie > results;
9+ @JsonKey (name: 'total_pages' )
10+ final int totalPages;
11+ @JsonKey (name: 'total_results' )
12+ final int totalResults;
13+
14+ MoviesResponse ({
15+ required this .page,
16+ required this .results,
17+ required this .totalPages,
18+ required this .totalResults,
19+ });
20+
21+ factory MoviesResponse .fromJson (Map <String , dynamic > json) =>
22+ _$MoviesResponseFromJson (json);
23+
24+ Map <String , dynamic > toJson () => _$MoviesResponseToJson (this );
25+ }
26+
27+ @JsonSerializable ()
28+ class Movie {
29+ final int id;
30+ final String title;
31+ @JsonKey (name: 'poster_path' )
32+ final String ? posterPath;
33+ @JsonKey (name: 'backdrop_path' )
34+ final String ? backdropPath;
35+ @JsonKey (name: 'release_date' )
36+ final String ? releaseDate;
37+ @JsonKey (name: 'vote_average' )
38+ final double voteAverage;
39+ final String overview;
40+
41+ Movie ({
42+ required this .id,
43+ required this .title,
44+ this .posterPath,
45+ this .backdropPath,
46+ this .releaseDate,
47+ required this .voteAverage,
48+ required this .overview,
49+ });
50+
51+ factory Movie .fromJson (Map <String , dynamic > json) => _$MovieFromJson (json);
52+
53+ Map <String , dynamic > toJson () => _$MovieToJson (this );
54+ }
55+
56+ @JsonSerializable ()
57+ class MovieDetailsResponse extends Movie {
58+ final List <Genre > genres;
59+ final int runtime;
60+ @JsonKey (name: 'production_companies' )
61+ final List <ProductionCompany > productionCompanies;
62+
63+ MovieDetailsResponse ({
64+ required super .id,
65+ required super .title,
66+ super .posterPath,
67+ super .backdropPath,
68+ super .releaseDate,
69+ required super .voteAverage,
70+ required super .overview,
71+ required this .genres,
72+ required this .runtime,
73+ required this .productionCompanies,
74+ });
75+
76+ factory MovieDetailsResponse .fromJson (Map <String , dynamic > json) =>
77+ _$MovieDetailsResponseFromJson (json);
78+
79+ @override
80+ Map <String , dynamic > toJson () => _$MovieDetailsResponseToJson (this );
81+ }
82+
83+ @JsonSerializable ()
84+ class Genre {
85+ final int id;
86+ final String name;
87+
88+ Genre ({required this .id, required this .name});
89+
90+ factory Genre .fromJson (Map <String , dynamic > json) => _$GenreFromJson (json);
91+
92+ Map <String , dynamic > toJson () => _$GenreToJson (this );
93+ }
94+
95+ @JsonSerializable ()
96+ class ProductionCompany {
97+ final int id;
98+ final String name;
99+ @JsonKey (name: 'logo_path' )
100+ final String ? logoPath;
101+ @JsonKey (name: 'origin_country' )
102+ final String originCountry;
103+
104+ ProductionCompany ({
105+ required this .id,
106+ required this .name,
107+ this .logoPath,
108+ required this .originCountry,
109+ });
110+
111+ factory ProductionCompany .fromJson (Map <String , dynamic > json) =>
112+ _$ProductionCompanyFromJson (json);
113+
114+ Map <String , dynamic > toJson () => _$ProductionCompanyToJson (this );
115+ }
116+
117+ @JsonSerializable ()
118+ class GenresResponse {
119+ final List <Genre > genres;
120+
121+ GenresResponse ({required this .genres});
122+
123+ factory GenresResponse .fromJson (Map <String , dynamic > json) =>
124+ _$GenresResponseFromJson (json);
125+
126+ Map <String , dynamic > toJson () => _$GenresResponseToJson (this );
127+ }
128+
129+ @JsonSerializable ()
130+ class CreditsResponse {
131+ final List <Cast > cast;
132+ final List <Crew > crew;
133+
134+ CreditsResponse ({required this .cast, required this .crew});
135+
136+ factory CreditsResponse .fromJson (Map <String , dynamic > json) =>
137+ _$CreditsResponseFromJson (json);
138+
139+ Map <String , dynamic > toJson () => _$CreditsResponseToJson (this );
140+ }
141+
142+ @JsonSerializable ()
143+ class Cast {
144+ final int id;
145+ final String name;
146+ final String character;
147+ @JsonKey (name: 'profile_path' )
148+ final String ? profilePath;
149+
150+ Cast ({
151+ required this .id,
152+ required this .name,
153+ required this .character,
154+ this .profilePath,
155+ });
156+
157+ factory Cast .fromJson (Map <String , dynamic > json) => _$CastFromJson (json);
158+
159+ Map <String , dynamic > toJson () => _$CastToJson (this );
160+ }
161+
162+ @JsonSerializable ()
163+ class Crew {
164+ final int id;
165+ final String name;
166+ final String department;
167+ final String job;
168+ @JsonKey (name: 'profile_path' )
169+ final String ? profilePath;
170+
171+ Crew ({
172+ required this .id,
173+ required this .name,
174+ required this .department,
175+ required this .job,
176+ this .profilePath,
177+ });
178+
179+ factory Crew .fromJson (Map <String , dynamic > json) => _$CrewFromJson (json);
180+
181+ Map <String , dynamic > toJson () => _$CrewToJson (this );
182+ }
0 commit comments