From 2c2e6d094115da30341d51e535b282cdf7a93920 Mon Sep 17 00:00:00 2001 From: krille-chan Date: Fri, 4 Oct 2024 17:53:56 +0200 Subject: [PATCH] chore: Follow up file selector --- lib/utils/file_selector.dart | 48 ++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/lib/utils/file_selector.dart b/lib/utils/file_selector.dart index fdbd0c0cb..f528f2cfd 100644 --- a/lib/utils/file_selector.dart +++ b/lib/utils/file_selector.dart @@ -18,9 +18,7 @@ Future> selectFiles( compressionQuality: 0, allowMultiple: allowMultiple, type: type.filePickerType, - allowedExtensions: type.filePickerType == FileType.custom - ? type.extensions?.toList() - : null, + allowedExtensions: type.extensions, ), ); return result?.xFiles ?? []; @@ -30,20 +28,14 @@ Future> selectFiles( return await AppLock.of(context).pauseWhile( openFiles( confirmButtonText: title, - acceptedTypeGroups: [ - if (type != FileSelectorType.any) - XTypeGroup(extensions: type.extensions?.toList()), - ], + acceptedTypeGroups: type.groups, ), ); } final file = await AppLock.of(context).pauseWhile( openFile( confirmButtonText: title, - acceptedTypeGroups: [ - if (type != FileSelectorType.any) - XTypeGroup(extensions: type.extensions?.toList()), - ], + acceptedTypeGroups: type.groups, ), ); if (file == null) return []; @@ -51,14 +43,38 @@ Future> selectFiles( } enum FileSelectorType { - any(null, FileType.any), + any([], FileType.any, null), images( - {'png', 'PNG', 'jpg', 'JPG', 'jpeg', 'JPEG', 'webp', 'WebP'}, + [ + XTypeGroup( + label: 'JPG', + extensions: ['jpg', 'JPG', 'jpeg', 'JPEG'], + ), + XTypeGroup( + label: 'PNGs', + extensions: ['png', 'PNG'], + ), + XTypeGroup( + label: 'WEBP', + extensions: ['WebP', 'WEBP'], + ), + ], FileType.image, + null, ), - zip({'zip', 'ZIP'}, FileType.custom); + zip( + [ + XTypeGroup( + label: 'ZIP', + extensions: ['zip', 'ZIP'], + ), + ], + FileType.custom, + ['zip', 'ZIP'], + ); - const FileSelectorType(this.extensions, this.filePickerType); - final Set? extensions; + const FileSelectorType(this.groups, this.filePickerType, this.extensions); + final List groups; final FileType filePickerType; + final List? extensions; }