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

190 lines
6.2 KiB
Dart
Raw Normal View History

import 'dart:async';
import 'package:flutter/foundation.dart';
import '../../data/services/torrent_platform_service.dart';
import '../../data/models/torrent_info.dart';
/// Provider для управления загрузками торрентов
class DownloadsProvider with ChangeNotifier {
final List<TorrentInfo> _torrents = [];
Timer? _progressTimer;
bool _isLoading = false;
String? _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;
List<TorrentInfo> get torrents => List.unmodifiable(_torrents);
bool get isLoading => _isLoading;
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? get stackTrace => _stackTrace;
DownloadsProvider() {
_startProgressUpdates();
}
@override
void dispose() {
_progressTimer?.cancel();
super.dispose();
}
void _startProgressUpdates() {
_progressTimer = Timer.periodic(const Duration(seconds: 3), (timer) {
if (_torrents.isNotEmpty && !_isLoading) {
refreshDownloads();
}
});
}
/// Загрузить список активных загрузок
Future<void> refreshDownloads() async {
feat: add comprehensive logging for downloads debugging Added extensive logging throughout DownloadsProvider and DownloadsScreen to diagnose why downloads screen appears empty. DownloadsProvider.refreshDownloads(): - 📥 Log function call - 📥 Log state changes (loading, error) - 📥 Log TorrentPlatformService.getAllDownloads() call - 📥 Log number of torrents received - 📥 Log each torrent processing with index - 📥 Log success/failure for each torrent info fetch - 📥 Log final torrents count - 📥 Log completion or error state DownloadsScreen.initState() and Consumer: - 📥 Log initState call - 📥 Log postFrameCallback execution - 📥 Log Consumer builder invocations - 📥 Log provider state (isLoading, error, torrents.length) - 📥 Log which UI is displayed: * CircularProgressIndicator * ErrorDisplay * Empty state message * Torrent list with count All logs prefixed with 📥 for easy filtering in logcat. Example output: --- 📥 DownloadsScreen: initState() called 📥 DownloadsScreen: postFrameCallback, calling refreshDownloads() 📥 DownloadsProvider: refreshDownloads() called 📥 Setting loading=true, error=null 📥 Calling TorrentPlatformService.getAllDownloads()... 📥 Got 0 torrents from platform service 📥 Cleared _torrents list 📥 Final torrents count: 0 📥 Setting loading=false 📥 ✅ refreshDownloads() completed successfully 📥 DownloadsScreen: Consumer builder called 📥 isLoading: false 📥 error: null 📥 torrents.length: 0 📥 → Showing empty state This will help identify: - Is refreshDownloads being called? - Does TorrentPlatformService return any data? - Are torrents parsed correctly? - Is the correct UI state shown? - Where does the process fail? Usage: Run app → Open Downloads screen → Check logcat for 📥 logs
2025-10-05 17:35:07 +00:00
print('📥 DownloadsProvider: refreshDownloads() called');
try {
feat: add comprehensive logging for downloads debugging Added extensive logging throughout DownloadsProvider and DownloadsScreen to diagnose why downloads screen appears empty. DownloadsProvider.refreshDownloads(): - 📥 Log function call - 📥 Log state changes (loading, error) - 📥 Log TorrentPlatformService.getAllDownloads() call - 📥 Log number of torrents received - 📥 Log each torrent processing with index - 📥 Log success/failure for each torrent info fetch - 📥 Log final torrents count - 📥 Log completion or error state DownloadsScreen.initState() and Consumer: - 📥 Log initState call - 📥 Log postFrameCallback execution - 📥 Log Consumer builder invocations - 📥 Log provider state (isLoading, error, torrents.length) - 📥 Log which UI is displayed: * CircularProgressIndicator * ErrorDisplay * Empty state message * Torrent list with count All logs prefixed with 📥 for easy filtering in logcat. Example output: --- 📥 DownloadsScreen: initState() called 📥 DownloadsScreen: postFrameCallback, calling refreshDownloads() 📥 DownloadsProvider: refreshDownloads() called 📥 Setting loading=true, error=null 📥 Calling TorrentPlatformService.getAllDownloads()... 📥 Got 0 torrents from platform service 📥 Cleared _torrents list 📥 Final torrents count: 0 📥 Setting loading=false 📥 ✅ refreshDownloads() completed successfully 📥 DownloadsScreen: Consumer builder called 📥 isLoading: false 📥 error: null 📥 torrents.length: 0 📥 → Showing empty state This will help identify: - Is refreshDownloads being called? - Does TorrentPlatformService return any data? - Are torrents parsed correctly? - Is the correct UI state shown? - Where does the process fail? Usage: Run app → Open Downloads screen → Check logcat for 📥 logs
2025-10-05 17:35:07 +00:00
print('📥 Setting loading=true, error=null');
_setLoading(true);
_setError(null);
feat: add comprehensive logging for downloads debugging Added extensive logging throughout DownloadsProvider and DownloadsScreen to diagnose why downloads screen appears empty. DownloadsProvider.refreshDownloads(): - 📥 Log function call - 📥 Log state changes (loading, error) - 📥 Log TorrentPlatformService.getAllDownloads() call - 📥 Log number of torrents received - 📥 Log each torrent processing with index - 📥 Log success/failure for each torrent info fetch - 📥 Log final torrents count - 📥 Log completion or error state DownloadsScreen.initState() and Consumer: - 📥 Log initState call - 📥 Log postFrameCallback execution - 📥 Log Consumer builder invocations - 📥 Log provider state (isLoading, error, torrents.length) - 📥 Log which UI is displayed: * CircularProgressIndicator * ErrorDisplay * Empty state message * Torrent list with count All logs prefixed with 📥 for easy filtering in logcat. Example output: --- 📥 DownloadsScreen: initState() called 📥 DownloadsScreen: postFrameCallback, calling refreshDownloads() 📥 DownloadsProvider: refreshDownloads() called 📥 Setting loading=true, error=null 📥 Calling TorrentPlatformService.getAllDownloads()... 📥 Got 0 torrents from platform service 📥 Cleared _torrents list 📥 Final torrents count: 0 📥 Setting loading=false 📥 ✅ refreshDownloads() completed successfully 📥 DownloadsScreen: Consumer builder called 📥 isLoading: false 📥 error: null 📥 torrents.length: 0 📥 → Showing empty state This will help identify: - Is refreshDownloads being called? - Does TorrentPlatformService return any data? - Are torrents parsed correctly? - Is the correct UI state shown? - Where does the process fail? Usage: Run app → Open Downloads screen → Check logcat for 📥 logs
2025-10-05 17:35:07 +00:00
print('📥 Calling TorrentPlatformService.getAllDownloads()...');
final progress = await TorrentPlatformService.getAllDownloads();
feat: add comprehensive logging for downloads debugging Added extensive logging throughout DownloadsProvider and DownloadsScreen to diagnose why downloads screen appears empty. DownloadsProvider.refreshDownloads(): - 📥 Log function call - 📥 Log state changes (loading, error) - 📥 Log TorrentPlatformService.getAllDownloads() call - 📥 Log number of torrents received - 📥 Log each torrent processing with index - 📥 Log success/failure for each torrent info fetch - 📥 Log final torrents count - 📥 Log completion or error state DownloadsScreen.initState() and Consumer: - 📥 Log initState call - 📥 Log postFrameCallback execution - 📥 Log Consumer builder invocations - 📥 Log provider state (isLoading, error, torrents.length) - 📥 Log which UI is displayed: * CircularProgressIndicator * ErrorDisplay * Empty state message * Torrent list with count All logs prefixed with 📥 for easy filtering in logcat. Example output: --- 📥 DownloadsScreen: initState() called 📥 DownloadsScreen: postFrameCallback, calling refreshDownloads() 📥 DownloadsProvider: refreshDownloads() called 📥 Setting loading=true, error=null 📥 Calling TorrentPlatformService.getAllDownloads()... 📥 Got 0 torrents from platform service 📥 Cleared _torrents list 📥 Final torrents count: 0 📥 Setting loading=false 📥 ✅ refreshDownloads() completed successfully 📥 DownloadsScreen: Consumer builder called 📥 isLoading: false 📥 error: null 📥 torrents.length: 0 📥 → Showing empty state This will help identify: - Is refreshDownloads being called? - Does TorrentPlatformService return any data? - Are torrents parsed correctly? - Is the correct UI state shown? - Where does the process fail? Usage: Run app → Open Downloads screen → Check logcat for 📥 logs
2025-10-05 17:35:07 +00:00
print('📥 Got ${progress.length} torrents from platform service');
// Получаем полную информацию о каждом торренте
_torrents.clear();
feat: add comprehensive logging for downloads debugging Added extensive logging throughout DownloadsProvider and DownloadsScreen to diagnose why downloads screen appears empty. DownloadsProvider.refreshDownloads(): - 📥 Log function call - 📥 Log state changes (loading, error) - 📥 Log TorrentPlatformService.getAllDownloads() call - 📥 Log number of torrents received - 📥 Log each torrent processing with index - 📥 Log success/failure for each torrent info fetch - 📥 Log final torrents count - 📥 Log completion or error state DownloadsScreen.initState() and Consumer: - 📥 Log initState call - 📥 Log postFrameCallback execution - 📥 Log Consumer builder invocations - 📥 Log provider state (isLoading, error, torrents.length) - 📥 Log which UI is displayed: * CircularProgressIndicator * ErrorDisplay * Empty state message * Torrent list with count All logs prefixed with 📥 for easy filtering in logcat. Example output: --- 📥 DownloadsScreen: initState() called 📥 DownloadsScreen: postFrameCallback, calling refreshDownloads() 📥 DownloadsProvider: refreshDownloads() called 📥 Setting loading=true, error=null 📥 Calling TorrentPlatformService.getAllDownloads()... 📥 Got 0 torrents from platform service 📥 Cleared _torrents list 📥 Final torrents count: 0 📥 Setting loading=false 📥 ✅ refreshDownloads() completed successfully 📥 DownloadsScreen: Consumer builder called 📥 isLoading: false 📥 error: null 📥 torrents.length: 0 📥 → Showing empty state This will help identify: - Is refreshDownloads being called? - Does TorrentPlatformService return any data? - Are torrents parsed correctly? - Is the correct UI state shown? - Where does the process fail? Usage: Run app → Open Downloads screen → Check logcat for 📥 logs
2025-10-05 17:35:07 +00:00
print('📥 Cleared _torrents list');
for (int i = 0; i < progress.length; i++) {
final progressItem = progress[i];
print('📥 Processing torrent $i: ${progressItem.infoHash.substring(0, 8)}...');
try {
final torrentInfo = await TorrentPlatformService.getTorrent(progressItem.infoHash);
if (torrentInfo != null) {
_torrents.add(torrentInfo);
}
} catch (e) {
// Если не удалось получить полную информацию, создаем базовую
_torrents.add(TorrentInfo(
infoHash: progressItem.infoHash,
name: 'Торрент ${progressItem.infoHash.substring(0, 8)}',
totalSize: 0,
progress: progressItem.progress,
downloadSpeed: progressItem.downloadRate,
uploadSpeed: progressItem.uploadRate,
numSeeds: progressItem.numSeeds,
numPeers: progressItem.numPeers,
state: progressItem.state,
savePath: '/storage/emulated/0/Download/NeoMovies',
files: [],
feat: add comprehensive logging for downloads debugging Added extensive logging throughout DownloadsProvider and DownloadsScreen to diagnose why downloads screen appears empty. DownloadsProvider.refreshDownloads(): - 📥 Log function call - 📥 Log state changes (loading, error) - 📥 Log TorrentPlatformService.getAllDownloads() call - 📥 Log number of torrents received - 📥 Log each torrent processing with index - 📥 Log success/failure for each torrent info fetch - 📥 Log final torrents count - 📥 Log completion or error state DownloadsScreen.initState() and Consumer: - 📥 Log initState call - 📥 Log postFrameCallback execution - 📥 Log Consumer builder invocations - 📥 Log provider state (isLoading, error, torrents.length) - 📥 Log which UI is displayed: * CircularProgressIndicator * ErrorDisplay * Empty state message * Torrent list with count All logs prefixed with 📥 for easy filtering in logcat. Example output: --- 📥 DownloadsScreen: initState() called 📥 DownloadsScreen: postFrameCallback, calling refreshDownloads() 📥 DownloadsProvider: refreshDownloads() called 📥 Setting loading=true, error=null 📥 Calling TorrentPlatformService.getAllDownloads()... 📥 Got 0 torrents from platform service 📥 Cleared _torrents list 📥 Final torrents count: 0 📥 Setting loading=false 📥 ✅ refreshDownloads() completed successfully 📥 DownloadsScreen: Consumer builder called 📥 isLoading: false 📥 error: null 📥 torrents.length: 0 📥 → Showing empty state This will help identify: - Is refreshDownloads being called? - Does TorrentPlatformService return any data? - Are torrents parsed correctly? - Is the correct UI state shown? - Where does the process fail? Usage: Run app → Open Downloads screen → Check logcat for 📥 logs
2025-10-05 17:35:07 +00:00
);
print('📥 ✅ Created basic info: ${basicInfo.name}');
_torrents.add(basicInfo);
}
}
feat: add comprehensive logging for downloads debugging Added extensive logging throughout DownloadsProvider and DownloadsScreen to diagnose why downloads screen appears empty. DownloadsProvider.refreshDownloads(): - 📥 Log function call - 📥 Log state changes (loading, error) - 📥 Log TorrentPlatformService.getAllDownloads() call - 📥 Log number of torrents received - 📥 Log each torrent processing with index - 📥 Log success/failure for each torrent info fetch - 📥 Log final torrents count - 📥 Log completion or error state DownloadsScreen.initState() and Consumer: - 📥 Log initState call - 📥 Log postFrameCallback execution - 📥 Log Consumer builder invocations - 📥 Log provider state (isLoading, error, torrents.length) - 📥 Log which UI is displayed: * CircularProgressIndicator * ErrorDisplay * Empty state message * Torrent list with count All logs prefixed with 📥 for easy filtering in logcat. Example output: --- 📥 DownloadsScreen: initState() called 📥 DownloadsScreen: postFrameCallback, calling refreshDownloads() 📥 DownloadsProvider: refreshDownloads() called 📥 Setting loading=true, error=null 📥 Calling TorrentPlatformService.getAllDownloads()... 📥 Got 0 torrents from platform service 📥 Cleared _torrents list 📥 Final torrents count: 0 📥 Setting loading=false 📥 ✅ refreshDownloads() completed successfully 📥 DownloadsScreen: Consumer builder called 📥 isLoading: false 📥 error: null 📥 torrents.length: 0 📥 → Showing empty state This will help identify: - Is refreshDownloads being called? - Does TorrentPlatformService return any data? - Are torrents parsed correctly? - Is the correct UI state shown? - Where does the process fail? Usage: Run app → Open Downloads screen → Check logcat for 📥 logs
2025-10-05 17:35:07 +00:00
print('📥 Final torrents count: ${_torrents.length}');
print('📥 Setting loading=false');
_setLoading(false);
feat: add comprehensive logging for downloads debugging Added extensive logging throughout DownloadsProvider and DownloadsScreen to diagnose why downloads screen appears empty. DownloadsProvider.refreshDownloads(): - 📥 Log function call - 📥 Log state changes (loading, error) - 📥 Log TorrentPlatformService.getAllDownloads() call - 📥 Log number of torrents received - 📥 Log each torrent processing with index - 📥 Log success/failure for each torrent info fetch - 📥 Log final torrents count - 📥 Log completion or error state DownloadsScreen.initState() and Consumer: - 📥 Log initState call - 📥 Log postFrameCallback execution - 📥 Log Consumer builder invocations - 📥 Log provider state (isLoading, error, torrents.length) - 📥 Log which UI is displayed: * CircularProgressIndicator * ErrorDisplay * Empty state message * Torrent list with count All logs prefixed with 📥 for easy filtering in logcat. Example output: --- 📥 DownloadsScreen: initState() called 📥 DownloadsScreen: postFrameCallback, calling refreshDownloads() 📥 DownloadsProvider: refreshDownloads() called 📥 Setting loading=true, error=null 📥 Calling TorrentPlatformService.getAllDownloads()... 📥 Got 0 torrents from platform service 📥 Cleared _torrents list 📥 Final torrents count: 0 📥 Setting loading=false 📥 ✅ refreshDownloads() completed successfully 📥 DownloadsScreen: Consumer builder called 📥 isLoading: false 📥 error: null 📥 torrents.length: 0 📥 → Showing empty state This will help identify: - Is refreshDownloads being called? - Does TorrentPlatformService return any data? - Are torrents parsed correctly? - Is the correct UI state shown? - Where does the process fail? Usage: Run app → Open Downloads screen → Check logcat for 📥 logs
2025-10-05 17:35:07 +00:00
print('📥 ✅ refreshDownloads() completed successfully');
} catch (e, stackTrace) {
print('📥 ❌ Error refreshing downloads: $e');
print('📥 Stack trace: $stackTrace');
_setError(e.toString(), stackTrace.toString());
_setLoading(false);
feat: add comprehensive logging for downloads debugging Added extensive logging throughout DownloadsProvider and DownloadsScreen to diagnose why downloads screen appears empty. DownloadsProvider.refreshDownloads(): - 📥 Log function call - 📥 Log state changes (loading, error) - 📥 Log TorrentPlatformService.getAllDownloads() call - 📥 Log number of torrents received - 📥 Log each torrent processing with index - 📥 Log success/failure for each torrent info fetch - 📥 Log final torrents count - 📥 Log completion or error state DownloadsScreen.initState() and Consumer: - 📥 Log initState call - 📥 Log postFrameCallback execution - 📥 Log Consumer builder invocations - 📥 Log provider state (isLoading, error, torrents.length) - 📥 Log which UI is displayed: * CircularProgressIndicator * ErrorDisplay * Empty state message * Torrent list with count All logs prefixed with 📥 for easy filtering in logcat. Example output: --- 📥 DownloadsScreen: initState() called 📥 DownloadsScreen: postFrameCallback, calling refreshDownloads() 📥 DownloadsProvider: refreshDownloads() called 📥 Setting loading=true, error=null 📥 Calling TorrentPlatformService.getAllDownloads()... 📥 Got 0 torrents from platform service 📥 Cleared _torrents list 📥 Final torrents count: 0 📥 Setting loading=false 📥 ✅ refreshDownloads() completed successfully 📥 DownloadsScreen: Consumer builder called 📥 isLoading: false 📥 error: null 📥 torrents.length: 0 📥 → Showing empty state This will help identify: - Is refreshDownloads being called? - Does TorrentPlatformService return any data? - Are torrents parsed correctly? - Is the correct UI state shown? - Where does the process fail? Usage: Run app → Open Downloads screen → Check logcat for 📥 logs
2025-10-05 17:35:07 +00:00
print('📥 Error state set, loading=false');
}
}
/// Получить информацию о конкретном торренте
Future<TorrentInfo?> getTorrentInfo(String infoHash) async {
try {
return await TorrentPlatformService.getTorrent(infoHash);
} catch (e) {
debugPrint('Ошибка получения информации о торренте: $e');
return null;
}
}
/// Приостановить торрент
Future<void> pauseTorrent(String infoHash) async {
try {
await TorrentPlatformService.pauseDownload(infoHash);
await refreshDownloads(); // Обновляем список
} catch (e) {
_setError(e.toString());
}
}
/// Возобновить торрент
Future<void> resumeTorrent(String infoHash) async {
try {
await TorrentPlatformService.resumeDownload(infoHash);
await refreshDownloads(); // Обновляем список
} catch (e) {
_setError(e.toString());
}
}
/// Удалить торрент
Future<void> removeTorrent(String infoHash) async {
try {
await TorrentPlatformService.cancelDownload(infoHash);
await refreshDownloads(); // Обновляем список
} catch (e) {
_setError(e.toString());
}
}
/// Установить приоритет файла
Future<void> setFilePriority(String infoHash, int fileIndex, FilePriority priority) async {
try {
await TorrentPlatformService.setFilePriority(infoHash, fileIndex, priority);
} catch (e) {
_setError(e.toString());
}
}
/// Добавить новый торрент
Future<String?> addTorrent(String magnetUri, {String? savePath}) async {
try {
final infoHash = await TorrentPlatformService.addTorrent(
magnetUri: magnetUri,
savePath: savePath,
);
await refreshDownloads(); // Обновляем список
return infoHash;
} catch (e) {
_setError(e.toString());
return null;
}
}
/// Форматировать скорость
String formatSpeed(int bytesPerSecond) {
if (bytesPerSecond < 1024) return '${bytesPerSecond}B/s';
if (bytesPerSecond < 1024 * 1024) return '${(bytesPerSecond / 1024).toStringAsFixed(1)}KB/s';
return '${(bytesPerSecond / (1024 * 1024)).toStringAsFixed(1)}MB/s';
}
/// Форматировать продолжительность
String formatDuration(Duration duration) {
final hours = duration.inHours;
final minutes = duration.inMinutes.remainder(60);
final seconds = duration.inSeconds.remainder(60);
if (hours > 0) {
return '${hours}ч ${minutes}м ${seconds}с';
} else if (minutes > 0) {
return '${minutes}м ${seconds}с';
} else {
return '${seconds}с';
}
}
void _setLoading(bool loading) {
_isLoading = loading;
notifyListeners();
}
void _setError(String? error, [String? stackTrace]) {
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
_error = error;
_stackTrace = stackTrace;
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
notifyListeners();
}
}