68 lines
1.8 KiB
Dart
68 lines
1.8 KiB
Dart
class Movie {
|
|
final int id;
|
|
final String title;
|
|
final String description;
|
|
final String imageUrl;
|
|
final String category;
|
|
final String director;
|
|
final String releaseDate;
|
|
final bool isFeatured;
|
|
final double rating;
|
|
final String originalTitle;
|
|
|
|
const Movie({
|
|
required this.id,
|
|
required this.title,
|
|
required this.description,
|
|
required this.imageUrl,
|
|
required this.category,
|
|
required this.director,
|
|
required this.releaseDate,
|
|
this.isFeatured = false,
|
|
this.rating = 0.0,
|
|
this.originalTitle = '',
|
|
});
|
|
|
|
factory Movie.fromJson(Map<String, dynamic> json) {
|
|
return Movie(
|
|
id: json['id'] ?? 0,
|
|
title: json['title'] ?? 'Titre inconnu',
|
|
description: json['overview'] ?? 'Description non disponible',
|
|
imageUrl: json['poster_path'] != null
|
|
? 'https://image.tmdb.org/t/p/w500${json['poster_path']}'
|
|
: '',
|
|
category: _getCategoryFromGenreIds(json['genre_ids'] ?? []),
|
|
director: 'Réalisateur inconnu',
|
|
releaseDate: json['release_date'] ?? 'Date inconnue',
|
|
rating: (json['vote_average'] ?? 0.0).toDouble(),
|
|
originalTitle: json['original_title'] ?? '',
|
|
);
|
|
}
|
|
|
|
static String _getCategoryFromGenreIds(List<dynamic> genreIds) {
|
|
if (genreIds.contains(28) || genreIds.contains(12)) return 'Action';
|
|
if (genreIds.contains(27)) return 'Horreur';
|
|
if (genreIds.contains(35)) return 'Comédie';
|
|
if (genreIds.contains(18)) return 'Drame';
|
|
if (genreIds.contains(37)) return 'Western';
|
|
return 'Autre';
|
|
}
|
|
}
|
|
|
|
class MovieCategory {
|
|
final String name;
|
|
final bool isSelected;
|
|
|
|
const MovieCategory({
|
|
required this.name,
|
|
this.isSelected = false,
|
|
});
|
|
|
|
MovieCategory copyWith({bool? isSelected}) {
|
|
return MovieCategory(
|
|
name: name,
|
|
isSelected: isSelected ?? this.isSelected,
|
|
);
|
|
}
|
|
}
|