FIX: Sort folders before files in file explorer

This commit is contained in:
Leon Bösche
2026-01-11 22:12:04 +01:00
parent 330bd86b96
commit 09d16abcd5

View File

@@ -267,6 +267,12 @@ class FileBrowserBloc extends Bloc<FileBrowserEvent, FileBrowserState> {
) {
final sorted = List<FileItem>.from(files);
sorted.sort((a, b) {
// Always put folders first, then files
if (a.type != b.type) {
return a.type == FileType.folder ? -1 : 1;
}
// Within the same type (both folders or both files), sort by the selected criterion
switch (sortBy) {
case 'name':
return isAscending
@@ -281,12 +287,7 @@ class FileBrowserBloc extends Bloc<FileBrowserEvent, FileBrowserState> {
? a.size.compareTo(b.size)
: b.size.compareTo(a.size);
case 'type':
// Folders before files if ascending, else files before folders
int typeCompare = isAscending
? a.type.index.compareTo(b.type.index)
: b.type.index.compareTo(a.type.index);
if (typeCompare != 0) return typeCompare;
// Within same type, sort by name
// Already handled above (folders vs files)
return isAscending
? a.name.compareTo(b.name)
: b.name.compareTo(a.name);