Refactor upload snackbar code for improved readability and maintainability
This commit is contained in:
@@ -37,7 +37,8 @@ class _FileExplorerState extends State<FileExplorer> {
|
|||||||
final TextEditingController _searchController = TextEditingController();
|
final TextEditingController _searchController = TextEditingController();
|
||||||
String _searchQuery = '';
|
String _searchQuery = '';
|
||||||
final Map<String, bool> _hovered = {};
|
final Map<String, bool> _hovered = {};
|
||||||
ScaffoldFeatureController<SnackBar, SnackBarClosedReason>? _uploadSnackBarController;
|
ScaffoldFeatureController<SnackBar, SnackBarClosedReason>?
|
||||||
|
_uploadSnackBarController;
|
||||||
|
|
||||||
String _getParentPath(String path) {
|
String _getParentPath(String path) {
|
||||||
if (path == '/') return '/';
|
if (path == '/') return '/';
|
||||||
@@ -687,9 +688,11 @@ class _FileExplorerState extends State<FileExplorer> {
|
|||||||
if (uploadState is UploadInProgress) {
|
if (uploadState is UploadInProgress) {
|
||||||
// Calculate overall progress
|
// Calculate overall progress
|
||||||
final uploads = uploadState.uploads;
|
final uploads = uploadState.uploads;
|
||||||
final activeUploads = uploads.where((u) => !u.isCompleted && u.error == null).toList();
|
final activeUploads = uploads
|
||||||
|
.where((u) => !u.isCompleted && u.error == null)
|
||||||
|
.toList();
|
||||||
final completedUploads = uploads.where((u) => u.isCompleted).toList();
|
final completedUploads = uploads.where((u) => u.isCompleted).toList();
|
||||||
|
|
||||||
// Show error if any upload failed
|
// Show error if any upload failed
|
||||||
for (final upload in uploads) {
|
for (final upload in uploads) {
|
||||||
if (upload.error != null && upload.error!.isNotEmpty) {
|
if (upload.error != null && upload.error!.isNotEmpty) {
|
||||||
@@ -698,14 +701,16 @@ class _FileExplorerState extends State<FileExplorer> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show progress snackbar for active uploads
|
// Show progress snackbar for active uploads
|
||||||
if (activeUploads.isNotEmpty) {
|
if (activeUploads.isNotEmpty) {
|
||||||
final totalProgress = uploads.fold<double>(0, (sum, u) => sum + u.progress) / uploads.length;
|
final totalProgress =
|
||||||
final fileName = activeUploads.length == 1
|
uploads.fold<double>(0, (sum, u) => sum + u.progress) /
|
||||||
? activeUploads.first.fileName
|
uploads.length;
|
||||||
|
final fileName = activeUploads.length == 1
|
||||||
|
? activeUploads.first.fileName
|
||||||
: '${activeUploads.length} files';
|
: '${activeUploads.length} files';
|
||||||
|
|
||||||
// Dismiss previous snackbar and show new one
|
// Dismiss previous snackbar and show new one
|
||||||
_uploadSnackBarController?.close();
|
_uploadSnackBarController?.close();
|
||||||
_uploadSnackBarController = ScaffoldMessenger.of(context).showSnackBar(
|
_uploadSnackBarController = ScaffoldMessenger.of(context).showSnackBar(
|
||||||
@@ -719,7 +724,9 @@ class _FileExplorerState extends State<FileExplorer> {
|
|||||||
value: totalProgress,
|
value: totalProgress,
|
||||||
strokeWidth: 2,
|
strokeWidth: 2,
|
||||||
color: AppTheme.accentColor,
|
color: AppTheme.accentColor,
|
||||||
backgroundColor: AppTheme.accentColor.withValues(alpha: 0.3),
|
backgroundColor: AppTheme.accentColor.withValues(
|
||||||
|
alpha: 0.3,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 12),
|
const SizedBox(width: 12),
|
||||||
@@ -732,17 +739,19 @@ class _FileExplorerState extends State<FileExplorer> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
duration: const Duration(days: 1), // Keep showing until dismissed
|
duration: const Duration(
|
||||||
backgroundColor: AppTheme.surfaceColor,
|
days: 1,
|
||||||
|
), // Keep showing until dismissed
|
||||||
|
backgroundColor: AppTheme.primaryBackground,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dismiss snackbar and refresh when all uploads complete
|
// Dismiss snackbar and refresh when all uploads complete
|
||||||
if (completedUploads.length == uploads.length && uploads.isNotEmpty) {
|
if (completedUploads.length == uploads.length && uploads.isNotEmpty) {
|
||||||
_uploadSnackBarController?.close();
|
_uploadSnackBarController?.close();
|
||||||
_uploadSnackBarController = null;
|
_uploadSnackBarController = null;
|
||||||
|
|
||||||
final fbState = context.read<FileBrowserBloc>().state;
|
final fbState = context.read<FileBrowserBloc>().state;
|
||||||
String currentPath = '/';
|
String currentPath = '/';
|
||||||
if (fbState is DirectoryLoaded) currentPath = fbState.currentPath;
|
if (fbState is DirectoryLoaded) currentPath = fbState.currentPath;
|
||||||
|
|||||||
Reference in New Issue
Block a user