Files
neomovies-mobile/lib/presentation/providers/movie_detail_provider.dart

83 lines
2.3 KiB
Dart
Raw Normal View History

2025-07-13 14:01:29 +03:00
import 'package:flutter/material.dart';
import 'package:neomovies_mobile/data/models/movie.dart';
import 'package:neomovies_mobile/data/repositories/movie_repository.dart';
import 'package:neomovies_mobile/data/api/api_client.dart';
class MovieDetailProvider with ChangeNotifier {
final MovieRepository _movieRepository;
final ApiClient _apiClient;
MovieDetailProvider(this._movieRepository, this._apiClient);
bool _isLoading = false;
bool get isLoading => _isLoading;
bool _isImdbLoading = false;
bool get isImdbLoading => _isImdbLoading;
Movie? _movie;
Movie? get movie => _movie;
String? _imdbId;
String? get imdbId => _imdbId;
String? _error;
String? get error => _error;
feat: add detailed error display widget for debugging Problem: - Gray screens without error messages made debugging impossible - Users couldn't see what went wrong - Developers couldn't debug issues without full stack traces Solution: 1. Created ErrorDisplay widget (lib/presentation/widgets/error_display.dart): ✅ Shows detailed error message with copy button ✅ Expandable stack trace section with syntax highlighting ✅ Retry button for failed operations ✅ Debug tips for troubleshooting ✅ Beautiful UI with icons, colors, and proper styling ✅ Fully selectable text for easy copying Features: - 🔴 Red error card with full error message - 🟠 Orange expandable stack trace panel - 🔵 Blue tips panel with debugging suggestions - 📋 Copy buttons for error and stack trace - 🔄 Retry button to attempt operation again - 📱 Responsive scrolling for long errors 2. Updated MovieDetailProvider: ✅ Added _stackTrace field to store full stack trace ✅ Save stack trace in catch block: catch (e, stackTrace) ✅ Expose via getter: String? get stackTrace 3. Updated DownloadsProvider: ✅ Added _stackTrace field ✅ Updated _setError() to accept optional stackTrace parameter ✅ Save stack trace in refreshDownloads() catch block ✅ Print error and stack trace to console 4. Updated MovieDetailScreen: ✅ Replaced simple Text('Error: ...') with ErrorDisplay widget ✅ Shows 'Ошибка загрузки фильма/сериала' title ✅ Pass error, stackTrace, and onRetry callback ✅ Retry attempts to reload media 5. Updated DownloadsScreen: ✅ Replaced custom error UI with ErrorDisplay widget ✅ Shows 'Ошибка загрузки торрентов' title ✅ Pass error, stackTrace, and onRetry callback ✅ Retry attempts to refresh downloads Error Display Features: ---------------------------- 📋 Сообщение об ошибке: [Red card with full error text] [Copy button] 🐛 Stack Trace (для разработчиков): [Expandable orange section] [Black terminal-style with green text] [Copy stack trace button] 💡 Советы по отладке: • Скопируйте ошибку и отправьте разработчику • Проверьте соединение с интернетом • Проверьте логи Flutter в консоли • Попробуйте перезапустить приложение 🔄 [Попробовать снова] button Example Error Display: ---------------------- ┌────────────────────────────────────┐ │ ⚠️ Произошла ошибка │ │ │ │ 📋 Сообщение об ошибке: │ │ ┌──────────────────────────────┐ │ │ │ Exception: Failed to load │ │ │ │ movie: 404 - Not Found │ │ │ │ [Копировать ошибку] │ │ │ └──────────────────────────────┘ │ │ │ │ 🐛 Stack Trace ▶ │ │ │ │ 💡 Советы по отладке: │ │ ┌──────────────────────────────┐ │ │ │ • Скопируйте ошибку... │ │ │ │ • Проверьте соединение... │ │ │ └──────────────────────────────┘ │ │ │ │ [🔄 Попробовать снова] │ └────────────────────────────────────┘ Changes: - lib/presentation/widgets/error_display.dart (NEW): 254 lines - lib/presentation/providers/movie_detail_provider.dart: +4 lines - lib/presentation/providers/downloads_provider.dart: +6 lines - lib/presentation/screens/movie_detail/movie_detail_screen.dart: +11/-2 lines - lib/presentation/screens/downloads/downloads_screen.dart: +4/-27 lines Result: ✅ No more gray screens without explanation! ✅ Full error messages visible on screen ✅ Stack traces available for developers ✅ Copy button for easy error reporting ✅ Retry button for quick recovery ✅ Beautiful, user-friendly error UI ✅ Much easier debugging process Testing: -------- 1. Open app and tap on a movie card 2. If error occurs, you'll see: - Full error message in red card - Stack trace in expandable section - Copy buttons for error and stack trace - Retry button to try again 3. Same for Downloads screen Now debugging is 10x easier! 🎉
2025-10-05 16:49:43 +00:00
String? _stackTrace;
String? get stackTrace => _stackTrace;
2025-07-13 14:01:29 +03:00
Future<void> loadMedia(int mediaId, String mediaType) async {
_isLoading = true;
_isImdbLoading = true;
_error = null;
_movie = null;
_imdbId = null;
notifyListeners();
try {
fix: resolve gray screens and add automatic versioning 1. Fix Downloads screen gray screen issue: - Add DownloadsProvider to main.dart providers list - Remove @RoutePage() decorator from DownloadsScreen - Downloads screen now displays torrent list correctly 2. Fix movie detail screen gray screen issue: - Improve Movie.fromJson() with better error handling - Safe parsing of genres field (handles both Map and String formats) - Add fallback 'Untitled' for movies without title - Add detailed logging in MovieDetailProvider - Better error messages with stack traces 3. Add automatic version update from CI/CD tags: - GitLab CI: Update pubspec.yaml version from CI_COMMIT_TAG before build - GitHub Actions: Update pubspec.yaml version from GITHUB_REF before build - Version format: tag v0.0.18 becomes version 0.0.18+18 - Applies to all build jobs (arm64, arm32, x64) How versioning works: - When you create tag v0.0.18, CI automatically updates pubspec.yaml - Build uses version 0.0.18+18 (version+buildNumber) - APK shows correct version in About screen and Google Play - No manual pubspec.yaml updates needed Example: - Create tag: git tag v0.0.18 && git push origin v0.0.18 - CI reads tag, extracts '0.0.18' - Updates: version: 0.0.18+18 in pubspec.yaml - Builds APK with this version - Release created with proper version number Changes: - lib/main.dart: Add DownloadsProvider - lib/presentation/screens/downloads/downloads_screen.dart: Remove @RoutePage - lib/data/models/movie.dart: Safe JSON parsing with error handling - lib/presentation/providers/movie_detail_provider.dart: Add detailed logging - .gitlab-ci.yml: Add version update script in all build jobs - .github/workflows/release.yml: Add version update step in all build jobs Result: ✅ Downloads screen displays properly ✅ Movie details screen loads correctly ✅ Automatic versioning from tags (0.0.18, 0.0.19, etc.) ✅ No more gray screens!
2025-10-05 16:28:47 +00:00
print('Loading media: ID=$mediaId, type=$mediaType');
2025-10-02 21:40:20 +00:00
// Load movie/TV details
2025-07-13 14:01:29 +03:00
if (mediaType == 'movie') {
_movie = await _movieRepository.getMovieById(mediaId.toString());
fix: resolve gray screens and add automatic versioning 1. Fix Downloads screen gray screen issue: - Add DownloadsProvider to main.dart providers list - Remove @RoutePage() decorator from DownloadsScreen - Downloads screen now displays torrent list correctly 2. Fix movie detail screen gray screen issue: - Improve Movie.fromJson() with better error handling - Safe parsing of genres field (handles both Map and String formats) - Add fallback 'Untitled' for movies without title - Add detailed logging in MovieDetailProvider - Better error messages with stack traces 3. Add automatic version update from CI/CD tags: - GitLab CI: Update pubspec.yaml version from CI_COMMIT_TAG before build - GitHub Actions: Update pubspec.yaml version from GITHUB_REF before build - Version format: tag v0.0.18 becomes version 0.0.18+18 - Applies to all build jobs (arm64, arm32, x64) How versioning works: - When you create tag v0.0.18, CI automatically updates pubspec.yaml - Build uses version 0.0.18+18 (version+buildNumber) - APK shows correct version in About screen and Google Play - No manual pubspec.yaml updates needed Example: - Create tag: git tag v0.0.18 && git push origin v0.0.18 - CI reads tag, extracts '0.0.18' - Updates: version: 0.0.18+18 in pubspec.yaml - Builds APK with this version - Release created with proper version number Changes: - lib/main.dart: Add DownloadsProvider - lib/presentation/screens/downloads/downloads_screen.dart: Remove @RoutePage - lib/data/models/movie.dart: Safe JSON parsing with error handling - lib/presentation/providers/movie_detail_provider.dart: Add detailed logging - .gitlab-ci.yml: Add version update script in all build jobs - .github/workflows/release.yml: Add version update step in all build jobs Result: ✅ Downloads screen displays properly ✅ Movie details screen loads correctly ✅ Automatic versioning from tags (0.0.18, 0.0.19, etc.) ✅ No more gray screens!
2025-10-05 16:28:47 +00:00
print('Movie loaded successfully: ${_movie?.title}');
2025-07-13 14:01:29 +03:00
} else {
_movie = await _movieRepository.getTvById(mediaId.toString());
fix: resolve gray screens and add automatic versioning 1. Fix Downloads screen gray screen issue: - Add DownloadsProvider to main.dart providers list - Remove @RoutePage() decorator from DownloadsScreen - Downloads screen now displays torrent list correctly 2. Fix movie detail screen gray screen issue: - Improve Movie.fromJson() with better error handling - Safe parsing of genres field (handles both Map and String formats) - Add fallback 'Untitled' for movies without title - Add detailed logging in MovieDetailProvider - Better error messages with stack traces 3. Add automatic version update from CI/CD tags: - GitLab CI: Update pubspec.yaml version from CI_COMMIT_TAG before build - GitHub Actions: Update pubspec.yaml version from GITHUB_REF before build - Version format: tag v0.0.18 becomes version 0.0.18+18 - Applies to all build jobs (arm64, arm32, x64) How versioning works: - When you create tag v0.0.18, CI automatically updates pubspec.yaml - Build uses version 0.0.18+18 (version+buildNumber) - APK shows correct version in About screen and Google Play - No manual pubspec.yaml updates needed Example: - Create tag: git tag v0.0.18 && git push origin v0.0.18 - CI reads tag, extracts '0.0.18' - Updates: version: 0.0.18+18 in pubspec.yaml - Builds APK with this version - Release created with proper version number Changes: - lib/main.dart: Add DownloadsProvider - lib/presentation/screens/downloads/downloads_screen.dart: Remove @RoutePage - lib/data/models/movie.dart: Safe JSON parsing with error handling - lib/presentation/providers/movie_detail_provider.dart: Add detailed logging - .gitlab-ci.yml: Add version update script in all build jobs - .github/workflows/release.yml: Add version update step in all build jobs Result: ✅ Downloads screen displays properly ✅ Movie details screen loads correctly ✅ Automatic versioning from tags (0.0.18, 0.0.19, etc.) ✅ No more gray screens!
2025-10-05 16:28:47 +00:00
print('TV show loaded successfully: ${_movie?.title}');
2025-07-13 14:01:29 +03:00
}
2025-10-02 21:40:20 +00:00
2025-07-13 14:01:29 +03:00
_isLoading = false;
notifyListeners();
2025-10-02 21:40:20 +00:00
// Try to load IMDb ID (non-blocking)
2025-07-13 14:01:29 +03:00
if (_movie != null) {
2025-10-02 21:40:20 +00:00
try {
fix: resolve gray screens and add automatic versioning 1. Fix Downloads screen gray screen issue: - Add DownloadsProvider to main.dart providers list - Remove @RoutePage() decorator from DownloadsScreen - Downloads screen now displays torrent list correctly 2. Fix movie detail screen gray screen issue: - Improve Movie.fromJson() with better error handling - Safe parsing of genres field (handles both Map and String formats) - Add fallback 'Untitled' for movies without title - Add detailed logging in MovieDetailProvider - Better error messages with stack traces 3. Add automatic version update from CI/CD tags: - GitLab CI: Update pubspec.yaml version from CI_COMMIT_TAG before build - GitHub Actions: Update pubspec.yaml version from GITHUB_REF before build - Version format: tag v0.0.18 becomes version 0.0.18+18 - Applies to all build jobs (arm64, arm32, x64) How versioning works: - When you create tag v0.0.18, CI automatically updates pubspec.yaml - Build uses version 0.0.18+18 (version+buildNumber) - APK shows correct version in About screen and Google Play - No manual pubspec.yaml updates needed Example: - Create tag: git tag v0.0.18 && git push origin v0.0.18 - CI reads tag, extracts '0.0.18' - Updates: version: 0.0.18+18 in pubspec.yaml - Builds APK with this version - Release created with proper version number Changes: - lib/main.dart: Add DownloadsProvider - lib/presentation/screens/downloads/downloads_screen.dart: Remove @RoutePage - lib/data/models/movie.dart: Safe JSON parsing with error handling - lib/presentation/providers/movie_detail_provider.dart: Add detailed logging - .gitlab-ci.yml: Add version update script in all build jobs - .github/workflows/release.yml: Add version update step in all build jobs Result: ✅ Downloads screen displays properly ✅ Movie details screen loads correctly ✅ Automatic versioning from tags (0.0.18, 0.0.19, etc.) ✅ No more gray screens!
2025-10-05 16:28:47 +00:00
print('Loading IMDb ID for $mediaType $mediaId');
2025-10-02 21:40:20 +00:00
_imdbId = await _apiClient.getImdbId(mediaId.toString(), mediaType);
fix: resolve gray screens and add automatic versioning 1. Fix Downloads screen gray screen issue: - Add DownloadsProvider to main.dart providers list - Remove @RoutePage() decorator from DownloadsScreen - Downloads screen now displays torrent list correctly 2. Fix movie detail screen gray screen issue: - Improve Movie.fromJson() with better error handling - Safe parsing of genres field (handles both Map and String formats) - Add fallback 'Untitled' for movies without title - Add detailed logging in MovieDetailProvider - Better error messages with stack traces 3. Add automatic version update from CI/CD tags: - GitLab CI: Update pubspec.yaml version from CI_COMMIT_TAG before build - GitHub Actions: Update pubspec.yaml version from GITHUB_REF before build - Version format: tag v0.0.18 becomes version 0.0.18+18 - Applies to all build jobs (arm64, arm32, x64) How versioning works: - When you create tag v0.0.18, CI automatically updates pubspec.yaml - Build uses version 0.0.18+18 (version+buildNumber) - APK shows correct version in About screen and Google Play - No manual pubspec.yaml updates needed Example: - Create tag: git tag v0.0.18 && git push origin v0.0.18 - CI reads tag, extracts '0.0.18' - Updates: version: 0.0.18+18 in pubspec.yaml - Builds APK with this version - Release created with proper version number Changes: - lib/main.dart: Add DownloadsProvider - lib/presentation/screens/downloads/downloads_screen.dart: Remove @RoutePage - lib/data/models/movie.dart: Safe JSON parsing with error handling - lib/presentation/providers/movie_detail_provider.dart: Add detailed logging - .gitlab-ci.yml: Add version update script in all build jobs - .github/workflows/release.yml: Add version update step in all build jobs Result: ✅ Downloads screen displays properly ✅ Movie details screen loads correctly ✅ Automatic versioning from tags (0.0.18, 0.0.19, etc.) ✅ No more gray screens!
2025-10-05 16:28:47 +00:00
print('IMDb ID loaded: $_imdbId');
2025-10-02 21:40:20 +00:00
} catch (e) {
// IMDb ID loading failed, but don't fail the whole screen
print('Failed to load IMDb ID: $e');
_imdbId = null;
}
2025-07-13 14:01:29 +03:00
}
fix: resolve gray screens and add automatic versioning 1. Fix Downloads screen gray screen issue: - Add DownloadsProvider to main.dart providers list - Remove @RoutePage() decorator from DownloadsScreen - Downloads screen now displays torrent list correctly 2. Fix movie detail screen gray screen issue: - Improve Movie.fromJson() with better error handling - Safe parsing of genres field (handles both Map and String formats) - Add fallback 'Untitled' for movies without title - Add detailed logging in MovieDetailProvider - Better error messages with stack traces 3. Add automatic version update from CI/CD tags: - GitLab CI: Update pubspec.yaml version from CI_COMMIT_TAG before build - GitHub Actions: Update pubspec.yaml version from GITHUB_REF before build - Version format: tag v0.0.18 becomes version 0.0.18+18 - Applies to all build jobs (arm64, arm32, x64) How versioning works: - When you create tag v0.0.18, CI automatically updates pubspec.yaml - Build uses version 0.0.18+18 (version+buildNumber) - APK shows correct version in About screen and Google Play - No manual pubspec.yaml updates needed Example: - Create tag: git tag v0.0.18 && git push origin v0.0.18 - CI reads tag, extracts '0.0.18' - Updates: version: 0.0.18+18 in pubspec.yaml - Builds APK with this version - Release created with proper version number Changes: - lib/main.dart: Add DownloadsProvider - lib/presentation/screens/downloads/downloads_screen.dart: Remove @RoutePage - lib/data/models/movie.dart: Safe JSON parsing with error handling - lib/presentation/providers/movie_detail_provider.dart: Add detailed logging - .gitlab-ci.yml: Add version update script in all build jobs - .github/workflows/release.yml: Add version update step in all build jobs Result: ✅ Downloads screen displays properly ✅ Movie details screen loads correctly ✅ Automatic versioning from tags (0.0.18, 0.0.19, etc.) ✅ No more gray screens!
2025-10-05 16:28:47 +00:00
} catch (e, stackTrace) {
2025-10-02 21:40:20 +00:00
print('Error loading media: $e');
fix: resolve gray screens and add automatic versioning 1. Fix Downloads screen gray screen issue: - Add DownloadsProvider to main.dart providers list - Remove @RoutePage() decorator from DownloadsScreen - Downloads screen now displays torrent list correctly 2. Fix movie detail screen gray screen issue: - Improve Movie.fromJson() with better error handling - Safe parsing of genres field (handles both Map and String formats) - Add fallback 'Untitled' for movies without title - Add detailed logging in MovieDetailProvider - Better error messages with stack traces 3. Add automatic version update from CI/CD tags: - GitLab CI: Update pubspec.yaml version from CI_COMMIT_TAG before build - GitHub Actions: Update pubspec.yaml version from GITHUB_REF before build - Version format: tag v0.0.18 becomes version 0.0.18+18 - Applies to all build jobs (arm64, arm32, x64) How versioning works: - When you create tag v0.0.18, CI automatically updates pubspec.yaml - Build uses version 0.0.18+18 (version+buildNumber) - APK shows correct version in About screen and Google Play - No manual pubspec.yaml updates needed Example: - Create tag: git tag v0.0.18 && git push origin v0.0.18 - CI reads tag, extracts '0.0.18' - Updates: version: 0.0.18+18 in pubspec.yaml - Builds APK with this version - Release created with proper version number Changes: - lib/main.dart: Add DownloadsProvider - lib/presentation/screens/downloads/downloads_screen.dart: Remove @RoutePage - lib/data/models/movie.dart: Safe JSON parsing with error handling - lib/presentation/providers/movie_detail_provider.dart: Add detailed logging - .gitlab-ci.yml: Add version update script in all build jobs - .github/workflows/release.yml: Add version update step in all build jobs Result: ✅ Downloads screen displays properly ✅ Movie details screen loads correctly ✅ Automatic versioning from tags (0.0.18, 0.0.19, etc.) ✅ No more gray screens!
2025-10-05 16:28:47 +00:00
print('Stack trace: $stackTrace');
2025-07-13 14:01:29 +03:00
_error = e.toString();
feat: add detailed error display widget for debugging Problem: - Gray screens without error messages made debugging impossible - Users couldn't see what went wrong - Developers couldn't debug issues without full stack traces Solution: 1. Created ErrorDisplay widget (lib/presentation/widgets/error_display.dart): ✅ Shows detailed error message with copy button ✅ Expandable stack trace section with syntax highlighting ✅ Retry button for failed operations ✅ Debug tips for troubleshooting ✅ Beautiful UI with icons, colors, and proper styling ✅ Fully selectable text for easy copying Features: - 🔴 Red error card with full error message - 🟠 Orange expandable stack trace panel - 🔵 Blue tips panel with debugging suggestions - 📋 Copy buttons for error and stack trace - 🔄 Retry button to attempt operation again - 📱 Responsive scrolling for long errors 2. Updated MovieDetailProvider: ✅ Added _stackTrace field to store full stack trace ✅ Save stack trace in catch block: catch (e, stackTrace) ✅ Expose via getter: String? get stackTrace 3. Updated DownloadsProvider: ✅ Added _stackTrace field ✅ Updated _setError() to accept optional stackTrace parameter ✅ Save stack trace in refreshDownloads() catch block ✅ Print error and stack trace to console 4. Updated MovieDetailScreen: ✅ Replaced simple Text('Error: ...') with ErrorDisplay widget ✅ Shows 'Ошибка загрузки фильма/сериала' title ✅ Pass error, stackTrace, and onRetry callback ✅ Retry attempts to reload media 5. Updated DownloadsScreen: ✅ Replaced custom error UI with ErrorDisplay widget ✅ Shows 'Ошибка загрузки торрентов' title ✅ Pass error, stackTrace, and onRetry callback ✅ Retry attempts to refresh downloads Error Display Features: ---------------------------- 📋 Сообщение об ошибке: [Red card with full error text] [Copy button] 🐛 Stack Trace (для разработчиков): [Expandable orange section] [Black terminal-style with green text] [Copy stack trace button] 💡 Советы по отладке: • Скопируйте ошибку и отправьте разработчику • Проверьте соединение с интернетом • Проверьте логи Flutter в консоли • Попробуйте перезапустить приложение 🔄 [Попробовать снова] button Example Error Display: ---------------------- ┌────────────────────────────────────┐ │ ⚠️ Произошла ошибка │ │ │ │ 📋 Сообщение об ошибке: │ │ ┌──────────────────────────────┐ │ │ │ Exception: Failed to load │ │ │ │ movie: 404 - Not Found │ │ │ │ [Копировать ошибку] │ │ │ └──────────────────────────────┘ │ │ │ │ 🐛 Stack Trace ▶ │ │ │ │ 💡 Советы по отладке: │ │ ┌──────────────────────────────┐ │ │ │ • Скопируйте ошибку... │ │ │ │ • Проверьте соединение... │ │ │ └──────────────────────────────┘ │ │ │ │ [🔄 Попробовать снова] │ └────────────────────────────────────┘ Changes: - lib/presentation/widgets/error_display.dart (NEW): 254 lines - lib/presentation/providers/movie_detail_provider.dart: +4 lines - lib/presentation/providers/downloads_provider.dart: +6 lines - lib/presentation/screens/movie_detail/movie_detail_screen.dart: +11/-2 lines - lib/presentation/screens/downloads/downloads_screen.dart: +4/-27 lines Result: ✅ No more gray screens without explanation! ✅ Full error messages visible on screen ✅ Stack traces available for developers ✅ Copy button for easy error reporting ✅ Retry button for quick recovery ✅ Beautiful, user-friendly error UI ✅ Much easier debugging process Testing: -------- 1. Open app and tap on a movie card 2. If error occurs, you'll see: - Full error message in red card - Stack trace in expandable section - Copy buttons for error and stack trace - Retry button to try again 3. Same for Downloads screen Now debugging is 10x easier! 🎉
2025-10-05 16:49:43 +00:00
_stackTrace = stackTrace.toString();
2025-07-13 14:01:29 +03:00
_isLoading = false;
2025-10-02 21:40:20 +00:00
notifyListeners();
} finally {
2025-07-13 14:01:29 +03:00
_isImdbLoading = false;
notifyListeners();
}
}
// Backward compatibility
Future<void> loadMovie(int movieId) async {
await loadMedia(movieId, 'movie');
}
}