chore: Follow up file selector

pull/1386/head^2
krille-chan 11 months ago
parent 811434e642
commit 2c2e6d0941
No known key found for this signature in database

@ -18,9 +18,7 @@ Future<List<XFile>> selectFiles(
compressionQuality: 0, compressionQuality: 0,
allowMultiple: allowMultiple, allowMultiple: allowMultiple,
type: type.filePickerType, type: type.filePickerType,
allowedExtensions: type.filePickerType == FileType.custom allowedExtensions: type.extensions,
? type.extensions?.toList()
: null,
), ),
); );
return result?.xFiles ?? []; return result?.xFiles ?? [];
@ -30,20 +28,14 @@ Future<List<XFile>> selectFiles(
return await AppLock.of(context).pauseWhile( return await AppLock.of(context).pauseWhile(
openFiles( openFiles(
confirmButtonText: title, confirmButtonText: title,
acceptedTypeGroups: [ acceptedTypeGroups: type.groups,
if (type != FileSelectorType.any)
XTypeGroup(extensions: type.extensions?.toList()),
],
), ),
); );
} }
final file = await AppLock.of(context).pauseWhile( final file = await AppLock.of(context).pauseWhile(
openFile( openFile(
confirmButtonText: title, confirmButtonText: title,
acceptedTypeGroups: [ acceptedTypeGroups: type.groups,
if (type != FileSelectorType.any)
XTypeGroup(extensions: type.extensions?.toList()),
],
), ),
); );
if (file == null) return []; if (file == null) return [];
@ -51,14 +43,38 @@ Future<List<XFile>> selectFiles(
} }
enum FileSelectorType { enum FileSelectorType {
any(null, FileType.any), any([], FileType.any, null),
images( images(
{'png', 'PNG', 'jpg', 'JPG', 'jpeg', 'JPEG', 'webp', 'WebP'}, [
XTypeGroup(
label: 'JPG',
extensions: <String>['jpg', 'JPG', 'jpeg', 'JPEG'],
),
XTypeGroup(
label: 'PNGs',
extensions: <String>['png', 'PNG'],
),
XTypeGroup(
label: 'WEBP',
extensions: <String>['WebP', 'WEBP'],
),
],
FileType.image, FileType.image,
null,
), ),
zip({'zip', 'ZIP'}, FileType.custom); zip(
[
XTypeGroup(
label: 'ZIP',
extensions: <String>['zip', 'ZIP'],
),
],
FileType.custom,
['zip', 'ZIP'],
);
const FileSelectorType(this.extensions, this.filePickerType); const FileSelectorType(this.groups, this.filePickerType, this.extensions);
final Set<String>? extensions; final List<XTypeGroup> groups;
final FileType filePickerType; final FileType filePickerType;
final List<String>? extensions;
} }

Loading…
Cancel
Save