From 233f1dd3158c3384e9e4e3319367a511db945435 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20B=C3=B6sche?= Date: Tue, 13 Jan 2026 16:50:09 +0100 Subject: [PATCH] Refactor upload snackbar code for improved readability and maintainability --- b0esche_cloud/lib/pages/file_explorer.dart | 35 ++++++++++++++-------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/b0esche_cloud/lib/pages/file_explorer.dart b/b0esche_cloud/lib/pages/file_explorer.dart index 5ce83a6..1e1e359 100644 --- a/b0esche_cloud/lib/pages/file_explorer.dart +++ b/b0esche_cloud/lib/pages/file_explorer.dart @@ -37,7 +37,8 @@ class _FileExplorerState extends State { final TextEditingController _searchController = TextEditingController(); String _searchQuery = ''; final Map _hovered = {}; - ScaffoldFeatureController? _uploadSnackBarController; + ScaffoldFeatureController? + _uploadSnackBarController; String _getParentPath(String path) { if (path == '/') return '/'; @@ -687,9 +688,11 @@ class _FileExplorerState extends State { if (uploadState is UploadInProgress) { // Calculate overall progress 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(); - + // Show error if any upload failed for (final upload in uploads) { if (upload.error != null && upload.error!.isNotEmpty) { @@ -698,14 +701,16 @@ class _FileExplorerState extends State { ); } } - + // Show progress snackbar for active uploads if (activeUploads.isNotEmpty) { - final totalProgress = uploads.fold(0, (sum, u) => sum + u.progress) / uploads.length; - final fileName = activeUploads.length == 1 - ? activeUploads.first.fileName + final totalProgress = + uploads.fold(0, (sum, u) => sum + u.progress) / + uploads.length; + final fileName = activeUploads.length == 1 + ? activeUploads.first.fileName : '${activeUploads.length} files'; - + // Dismiss previous snackbar and show new one _uploadSnackBarController?.close(); _uploadSnackBarController = ScaffoldMessenger.of(context).showSnackBar( @@ -719,7 +724,9 @@ class _FileExplorerState extends State { value: totalProgress, strokeWidth: 2, color: AppTheme.accentColor, - backgroundColor: AppTheme.accentColor.withValues(alpha: 0.3), + backgroundColor: AppTheme.accentColor.withValues( + alpha: 0.3, + ), ), ), const SizedBox(width: 12), @@ -732,17 +739,19 @@ class _FileExplorerState extends State { ), ], ), - duration: const Duration(days: 1), // Keep showing until dismissed - backgroundColor: AppTheme.surfaceColor, + duration: const Duration( + days: 1, + ), // Keep showing until dismissed + backgroundColor: AppTheme.primaryBackground, ), ); } - + // Dismiss snackbar and refresh when all uploads complete if (completedUploads.length == uploads.length && uploads.isNotEmpty) { _uploadSnackBarController?.close(); _uploadSnackBarController = null; - + final fbState = context.read().state; String currentPath = '/'; if (fbState is DirectoryLoaded) currentPath = fbState.currentPath;