From fd296d800f0f9d00b9efca4955c7d5a785e6e2a6 Mon Sep 17 00:00:00 2001 From: "factory-droid[bot]" <138933559+factory-droid[bot]@users.noreply.github.com> Date: Thu, 2 Oct 2025 21:40:20 +0000 Subject: [PATCH] fix api bugs --- lib/data/models/favorite.dart | 7 +++--- lib/data/models/movie.dart | 25 +++++++++++++++---- lib/data/models/movie.g.dart | 2 ++ .../providers/movie_detail_provider.dart | 15 +++++++++-- 4 files changed, 39 insertions(+), 10 deletions(-) diff --git a/lib/data/models/favorite.dart b/lib/data/models/favorite.dart index adcb887..a1ee481 100644 --- a/lib/data/models/favorite.dart +++ b/lib/data/models/favorite.dart @@ -31,11 +31,12 @@ class Favorite { } String get fullPosterUrl { - final baseUrl = dotenv.env['API_URL']!; if (posterPath.isEmpty) { - return '$baseUrl/images/w500/placeholder.jpg'; + return 'https://via.placeholder.com/500x750.png?text=No+Poster'; } + // TMDB CDN base URL + const tmdbBaseUrl = 'https://image.tmdb.org/t/p'; final cleanPath = posterPath.startsWith('/') ? posterPath.substring(1) : posterPath; - return '$baseUrl/images/w500/$cleanPath'; + return '$tmdbBaseUrl/w500/$cleanPath'; } } diff --git a/lib/data/models/movie.dart b/lib/data/models/movie.dart index 2347008..f8ed7e5 100644 --- a/lib/data/models/movie.dart +++ b/lib/data/models/movie.dart @@ -16,6 +16,8 @@ class Movie extends HiveObject { @HiveField(2) final String? posterPath; + final String? backdropPath; + @HiveField(3) final String? overview; @@ -51,6 +53,7 @@ class Movie extends HiveObject { required this.id, required this.title, this.posterPath, + this.backdropPath, this.overview, this.releaseDate, this.genres, @@ -68,6 +71,7 @@ class Movie extends HiveObject { id: (json['id'] as num).toString(), // Ensure id is a string title: (json['title'] ?? json['name'] ?? '') as String, posterPath: json['poster_path'] as String?, + backdropPath: json['backdrop_path'] as String?, overview: json['overview'] as String?, releaseDate: json['release_date'] != null && json['release_date'].isNotEmpty ? DateTime.tryParse(json['release_date'] as String) @@ -92,13 +96,24 @@ class Movie extends HiveObject { Map toJson() => _$MovieToJson(this); String get fullPosterUrl { - final baseUrl = dotenv.env['API_URL']!; if (posterPath == null || posterPath!.isEmpty) { - // Use the placeholder from our own backend - return '$baseUrl/images/w500/placeholder.jpg'; + // Use a generic placeholder + return 'https://via.placeholder.com/500x750.png?text=No+Poster'; } - // Null check is already performed above, so we can use `!` + // TMDB CDN base URL + const tmdbBaseUrl = 'https://image.tmdb.org/t/p'; final cleanPath = posterPath!.startsWith('/') ? posterPath!.substring(1) : posterPath!; - return '$baseUrl/images/w500/$cleanPath'; + return '$tmdbBaseUrl/w500/$cleanPath'; + } + + String get fullBackdropUrl { + if (backdropPath == null || backdropPath!.isEmpty) { + // Use a generic placeholder + return 'https://via.placeholder.com/1280x720.png?text=No+Backdrop'; + } + // TMDB CDN base URL + const tmdbBaseUrl = 'https://image.tmdb.org/t/p'; + final cleanPath = backdropPath!.startsWith('/') ? backdropPath!.substring(1) : backdropPath!; + return '$tmdbBaseUrl/w780/$cleanPath'; } } diff --git a/lib/data/models/movie.g.dart b/lib/data/models/movie.g.dart index ef9e953..5596444 100644 --- a/lib/data/models/movie.g.dart +++ b/lib/data/models/movie.g.dart @@ -81,6 +81,7 @@ Movie _$MovieFromJson(Map json) => Movie( id: json['id'] as String, title: json['title'] as String, posterPath: json['posterPath'] as String?, + backdropPath: json['backdropPath'] as String?, overview: json['overview'] as String?, releaseDate: json['releaseDate'] == null ? null @@ -100,6 +101,7 @@ Map _$MovieToJson(Movie instance) => { 'id': instance.id, 'title': instance.title, 'posterPath': instance.posterPath, + 'backdropPath': instance.backdropPath, 'overview': instance.overview, 'releaseDate': instance.releaseDate?.toIso8601String(), 'genres': instance.genres, diff --git a/lib/presentation/providers/movie_detail_provider.dart b/lib/presentation/providers/movie_detail_provider.dart index 3110ad3..c5a351b 100644 --- a/lib/presentation/providers/movie_detail_provider.dart +++ b/lib/presentation/providers/movie_detail_provider.dart @@ -33,21 +33,32 @@ class MovieDetailProvider with ChangeNotifier { notifyListeners(); try { + // Load movie/TV details if (mediaType == 'movie') { _movie = await _movieRepository.getMovieById(mediaId.toString()); } else { _movie = await _movieRepository.getTvById(mediaId.toString()); } + _isLoading = false; notifyListeners(); + // Try to load IMDb ID (non-blocking) if (_movie != null) { - _imdbId = await _apiClient.getImdbId(mediaId.toString(), mediaType); + try { + _imdbId = await _apiClient.getImdbId(mediaId.toString(), mediaType); + } catch (e) { + // IMDb ID loading failed, but don't fail the whole screen + print('Failed to load IMDb ID: $e'); + _imdbId = null; + } } } catch (e) { + print('Error loading media: $e'); _error = e.toString(); - } finally { _isLoading = false; + notifyListeners(); + } finally { _isImdbLoading = false; notifyListeners(); }