pickMultiple method
Future<List<PickerValue> >
pickMultiple({
- String? dialogTitle,
- PickerFileType type = PickerFileType.any,
override
Implement a process to pick up multiple files.
The title of the file dialog to be picked up is passed in dialogTitle
.
Please specify type
to restrict the type of file.
複数のファイルをピックアップするための処理を実装してください。
dialogTitle
でピックアップする際のファイルダイアログのタイトルが渡されます。
type
を指定するとファイルの種類を制限するようにしてください。
Implementation
@override
Future<List<PickerValue>> pickMultiple({
String? dialogTitle,
PickerFileType type = PickerFileType.any,
}) async {
switch (type) {
case PickerFileType.image:
final res = await FilePicker.platform.pickFiles(
allowMultiple: true,
dialogTitle: dialogTitle,
type: FileType.image,
);
final files = res?.files;
if (files == null) {
throw Exception("File not found.");
}
return files.mapAndRemoveEmpty((file) {
if (file.path == null && file.bytes == null) {
return null;
}
return PickerValue(path: file.path, bytes: file.bytes);
});
case PickerFileType.video:
final res = await FilePicker.platform.pickFiles(
allowMultiple: true,
dialogTitle: dialogTitle,
type: FileType.video,
);
final files = res?.files;
if (files == null) {
throw Exception("File not found.");
}
return files.mapAndRemoveEmpty((file) {
if (file.path == null && file.bytes == null) {
return null;
}
return PickerValue(path: file.path, bytes: file.bytes);
});
default:
final res = await FilePicker.platform.pickFiles(
allowMultiple: true,
dialogTitle: dialogTitle,
);
final files = res?.files;
if (files == null) {
throw Exception("File not found.");
}
return files.mapAndRemoveEmpty((file) {
if (file.path == null && file.bytes == null) {
return null;
}
return PickerValue(path: file.path, bytes: file.bytes);
});
}
}