Refactor upload snackbar code for improved readability and maintainability

This commit is contained in:
Leon Bösche
2026-01-13 16:50:09 +01:00
parent d2c26e6203
commit 233f1dd315

View File

@@ -37,7 +37,8 @@ class _FileExplorerState extends State<FileExplorer> {
final TextEditingController _searchController = TextEditingController();
String _searchQuery = '';
final Map<String, bool> _hovered = {};
ScaffoldFeatureController<SnackBar, SnackBarClosedReason>? _uploadSnackBarController;
ScaffoldFeatureController<SnackBar, SnackBarClosedReason>?
_uploadSnackBarController;
String _getParentPath(String path) {
if (path == '/') return '/';
@@ -687,7 +688,9 @@ class _FileExplorerState extends State<FileExplorer> {
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
@@ -701,7 +704,9 @@ class _FileExplorerState extends State<FileExplorer> {
// Show progress snackbar for active uploads
if (activeUploads.isNotEmpty) {
final totalProgress = uploads.fold<double>(0, (sum, u) => sum + u.progress) / uploads.length;
final totalProgress =
uploads.fold<double>(0, (sum, u) => sum + u.progress) /
uploads.length;
final fileName = activeUploads.length == 1
? activeUploads.first.fileName
: '${activeUploads.length} files';
@@ -719,7 +724,9 @@ class _FileExplorerState extends State<FileExplorer> {
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,8 +739,10 @@ class _FileExplorerState extends State<FileExplorer> {
),
],
),
duration: const Duration(days: 1), // Keep showing until dismissed
backgroundColor: AppTheme.surfaceColor,
duration: const Duration(
days: 1,
), // Keep showing until dismissed
backgroundColor: AppTheme.primaryBackground,
),
);
}