mirror of
https://gitlab.com/foxixus/neomovies_mobile.git
synced 2025-10-27 19:58:50 +05:00
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! 🎉
419 lines
13 KiB
Dart
419 lines
13 KiB
Dart
import 'package:flutter/material.dart';
|
||
import 'package:provider/provider.dart';
|
||
import '../../providers/downloads_provider.dart';
|
||
import '../../widgets/error_display.dart';
|
||
import '../../../data/models/torrent_info.dart';
|
||
import 'torrent_detail_screen.dart';
|
||
|
||
class DownloadsScreen extends StatefulWidget {
|
||
const DownloadsScreen({super.key});
|
||
|
||
@override
|
||
State<DownloadsScreen> createState() => _DownloadsScreenState();
|
||
}
|
||
|
||
class _DownloadsScreenState extends State<DownloadsScreen> {
|
||
@override
|
||
void initState() {
|
||
super.initState();
|
||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||
context.read<DownloadsProvider>().refreshDownloads();
|
||
});
|
||
}
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return Scaffold(
|
||
appBar: AppBar(
|
||
title: const Text('Загрузки'),
|
||
elevation: 0,
|
||
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
||
foregroundColor: Theme.of(context).textTheme.titleLarge?.color,
|
||
actions: [
|
||
IconButton(
|
||
icon: const Icon(Icons.refresh),
|
||
onPressed: () {
|
||
context.read<DownloadsProvider>().refreshDownloads();
|
||
},
|
||
),
|
||
],
|
||
),
|
||
body: Consumer<DownloadsProvider>(
|
||
builder: (context, provider, child) {
|
||
if (provider.isLoading) {
|
||
return const Center(
|
||
child: CircularProgressIndicator(),
|
||
);
|
||
}
|
||
|
||
if (provider.error != null) {
|
||
return ErrorDisplay(
|
||
title: 'Ошибка загрузки торрентов',
|
||
error: provider.error!,
|
||
stackTrace: provider.stackTrace,
|
||
onRetry: () {
|
||
provider.refreshDownloads();
|
||
},
|
||
);
|
||
}
|
||
|
||
if (provider.torrents.isEmpty) {
|
||
return Center(
|
||
child: Column(
|
||
mainAxisAlignment: MainAxisAlignment.center,
|
||
children: [
|
||
Icon(
|
||
Icons.download_outlined,
|
||
size: 64,
|
||
color: Colors.grey.shade400,
|
||
),
|
||
const SizedBox(height: 16),
|
||
Text(
|
||
'Нет активных загрузок',
|
||
style: Theme.of(context).textTheme.headlineSmall?.copyWith(
|
||
color: Colors.grey.shade600,
|
||
),
|
||
),
|
||
const SizedBox(height: 8),
|
||
Text(
|
||
'Загруженные торренты будут отображаться здесь',
|
||
textAlign: TextAlign.center,
|
||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||
color: Colors.grey.shade500,
|
||
),
|
||
),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
|
||
return RefreshIndicator(
|
||
onRefresh: () async {
|
||
await provider.refreshDownloads();
|
||
},
|
||
child: ListView.builder(
|
||
padding: const EdgeInsets.all(16),
|
||
itemCount: provider.torrents.length,
|
||
itemBuilder: (context, index) {
|
||
final torrent = provider.torrents[index];
|
||
return TorrentListItem(
|
||
torrent: torrent,
|
||
onTap: () {
|
||
Navigator.push(
|
||
context,
|
||
MaterialPageRoute(
|
||
builder: (context) => TorrentDetailScreen(
|
||
infoHash: torrent.infoHash,
|
||
),
|
||
),
|
||
);
|
||
},
|
||
onMenuPressed: (action) {
|
||
_handleTorrentAction(action, torrent);
|
||
},
|
||
);
|
||
},
|
||
),
|
||
);
|
||
},
|
||
),
|
||
);
|
||
}
|
||
|
||
void _handleTorrentAction(TorrentAction action, TorrentInfo torrent) {
|
||
final provider = context.read<DownloadsProvider>();
|
||
|
||
switch (action) {
|
||
case TorrentAction.pause:
|
||
provider.pauseTorrent(torrent.infoHash);
|
||
break;
|
||
case TorrentAction.resume:
|
||
provider.resumeTorrent(torrent.infoHash);
|
||
break;
|
||
case TorrentAction.remove:
|
||
_showRemoveConfirmation(torrent);
|
||
break;
|
||
case TorrentAction.openFolder:
|
||
_openFolder(torrent);
|
||
break;
|
||
}
|
||
}
|
||
|
||
void _showRemoveConfirmation(TorrentInfo torrent) {
|
||
showDialog(
|
||
context: context,
|
||
builder: (BuildContext context) {
|
||
return AlertDialog(
|
||
title: const Text('Удалить торрент'),
|
||
content: Text(
|
||
'Вы уверены, что хотите удалить "${torrent.name}"?\n\nФайлы будут удалены с устройства.',
|
||
),
|
||
actions: [
|
||
TextButton(
|
||
onPressed: () => Navigator.of(context).pop(),
|
||
child: const Text('Отмена'),
|
||
),
|
||
TextButton(
|
||
onPressed: () {
|
||
Navigator.of(context).pop();
|
||
context.read<DownloadsProvider>().removeTorrent(torrent.infoHash);
|
||
},
|
||
style: TextButton.styleFrom(
|
||
foregroundColor: Colors.red,
|
||
),
|
||
child: const Text('Удалить'),
|
||
),
|
||
],
|
||
);
|
||
},
|
||
);
|
||
}
|
||
|
||
void _openFolder(TorrentInfo torrent) {
|
||
ScaffoldMessenger.of(context).showSnackBar(
|
||
SnackBar(
|
||
content: Text('Папка: ${torrent.savePath}'),
|
||
action: SnackBarAction(
|
||
label: 'Копировать',
|
||
onPressed: () {
|
||
// TODO: Copy path to clipboard
|
||
},
|
||
),
|
||
),
|
||
);
|
||
}
|
||
}
|
||
|
||
enum TorrentAction { pause, resume, remove, openFolder }
|
||
|
||
class TorrentListItem extends StatelessWidget {
|
||
final TorrentInfo torrent;
|
||
final VoidCallback onTap;
|
||
final Function(TorrentAction) onMenuPressed;
|
||
|
||
const TorrentListItem({
|
||
super.key,
|
||
required this.torrent,
|
||
required this.onTap,
|
||
required this.onMenuPressed,
|
||
});
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return Card(
|
||
margin: const EdgeInsets.only(bottom: 12),
|
||
child: InkWell(
|
||
onTap: onTap,
|
||
borderRadius: BorderRadius.circular(12),
|
||
child: Padding(
|
||
padding: const EdgeInsets.all(16),
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
Row(
|
||
children: [
|
||
Expanded(
|
||
child: Text(
|
||
torrent.name,
|
||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||
fontWeight: FontWeight.w600,
|
||
),
|
||
maxLines: 2,
|
||
overflow: TextOverflow.ellipsis,
|
||
),
|
||
),
|
||
const SizedBox(width: 8),
|
||
PopupMenuButton<TorrentAction>(
|
||
icon: const Icon(Icons.more_vert),
|
||
onSelected: onMenuPressed,
|
||
itemBuilder: (BuildContext context) => [
|
||
if (torrent.isPaused)
|
||
const PopupMenuItem(
|
||
value: TorrentAction.resume,
|
||
child: Row(
|
||
children: [
|
||
Icon(Icons.play_arrow),
|
||
SizedBox(width: 8),
|
||
Text('Возобновить'),
|
||
],
|
||
),
|
||
)
|
||
else
|
||
const PopupMenuItem(
|
||
value: TorrentAction.pause,
|
||
child: Row(
|
||
children: [
|
||
Icon(Icons.pause),
|
||
SizedBox(width: 8),
|
||
Text('Приостановить'),
|
||
],
|
||
),
|
||
),
|
||
const PopupMenuItem(
|
||
value: TorrentAction.openFolder,
|
||
child: Row(
|
||
children: [
|
||
Icon(Icons.folder_open),
|
||
SizedBox(width: 8),
|
||
Text('Открыть папку'),
|
||
],
|
||
),
|
||
),
|
||
const PopupMenuItem(
|
||
value: TorrentAction.remove,
|
||
child: Row(
|
||
children: [
|
||
Icon(Icons.delete, color: Colors.red),
|
||
SizedBox(width: 8),
|
||
Text('Удалить', style: TextStyle(color: Colors.red)),
|
||
],
|
||
),
|
||
),
|
||
],
|
||
),
|
||
],
|
||
),
|
||
const SizedBox(height: 12),
|
||
_buildProgressBar(context),
|
||
const SizedBox(height: 8),
|
||
Row(
|
||
children: [
|
||
_buildStatusChip(),
|
||
const Spacer(),
|
||
Text(
|
||
torrent.formattedTotalSize,
|
||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||
color: Colors.grey.shade600,
|
||
),
|
||
),
|
||
],
|
||
),
|
||
if (torrent.isDownloading || torrent.isSeeding) ...[
|
||
const SizedBox(height: 8),
|
||
Row(
|
||
children: [
|
||
Icon(
|
||
Icons.download,
|
||
size: 16,
|
||
color: Colors.green.shade600,
|
||
),
|
||
const SizedBox(width: 4),
|
||
Text(
|
||
torrent.formattedDownloadSpeed,
|
||
style: Theme.of(context).textTheme.bodySmall,
|
||
),
|
||
const SizedBox(width: 16),
|
||
Icon(
|
||
Icons.upload,
|
||
size: 16,
|
||
color: Colors.blue.shade600,
|
||
),
|
||
const SizedBox(width: 4),
|
||
Text(
|
||
torrent.formattedUploadSpeed,
|
||
style: Theme.of(context).textTheme.bodySmall,
|
||
),
|
||
const Spacer(),
|
||
Text(
|
||
'S: ${torrent.numSeeds} P: ${torrent.numPeers}',
|
||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||
color: Colors.grey.shade600,
|
||
),
|
||
),
|
||
],
|
||
),
|
||
],
|
||
],
|
||
),
|
||
),
|
||
),
|
||
);
|
||
}
|
||
|
||
Widget _buildProgressBar(BuildContext context) {
|
||
return Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
Row(
|
||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||
children: [
|
||
Text(
|
||
'Прогресс',
|
||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||
color: Colors.grey.shade600,
|
||
),
|
||
),
|
||
Text(
|
||
'${(torrent.progress * 100).toStringAsFixed(1)}%',
|
||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||
fontWeight: FontWeight.w600,
|
||
),
|
||
),
|
||
],
|
||
),
|
||
const SizedBox(height: 4),
|
||
LinearProgressIndicator(
|
||
value: torrent.progress,
|
||
backgroundColor: Colors.grey.shade300,
|
||
valueColor: AlwaysStoppedAnimation<Color>(
|
||
torrent.isCompleted
|
||
? Colors.green.shade600
|
||
: Theme.of(context).primaryColor,
|
||
),
|
||
),
|
||
],
|
||
);
|
||
}
|
||
|
||
Widget _buildStatusChip() {
|
||
Color color;
|
||
IconData icon;
|
||
String text;
|
||
|
||
if (torrent.isCompleted) {
|
||
color = Colors.green;
|
||
icon = Icons.check_circle;
|
||
text = 'Завершен';
|
||
} else if (torrent.isDownloading) {
|
||
color = Colors.blue;
|
||
icon = Icons.download;
|
||
text = 'Загружается';
|
||
} else if (torrent.isPaused) {
|
||
color = Colors.orange;
|
||
icon = Icons.pause;
|
||
text = 'Приостановлен';
|
||
} else if (torrent.isSeeding) {
|
||
color = Colors.purple;
|
||
icon = Icons.upload;
|
||
text = 'Раздача';
|
||
} else {
|
||
color = Colors.grey;
|
||
icon = Icons.help_outline;
|
||
text = torrent.state;
|
||
}
|
||
|
||
return Container(
|
||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||
decoration: BoxDecoration(
|
||
color: color.withOpacity(0.1),
|
||
borderRadius: BorderRadius.circular(12),
|
||
border: Border.all(color: color.withOpacity(0.3)),
|
||
),
|
||
child: Row(
|
||
mainAxisSize: MainAxisSize.min,
|
||
children: [
|
||
Icon(icon, size: 14, color: color),
|
||
const SizedBox(width: 4),
|
||
Text(
|
||
text,
|
||
style: TextStyle(
|
||
color: color,
|
||
fontSize: 12,
|
||
fontWeight: FontWeight.w500,
|
||
),
|
||
),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
} |