pickSingle method
Future<PickerValue>
pickSingle({
- String? dialogTitle,
- PickerFileType type = PickerFileType.any,
override
Implement a process to pick up single 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<PickerValue> pickSingle({
String? dialogTitle,
PickerFileType type = PickerFileType.any,
}) async {
switch (type) {
case PickerFileType.image:
final res = await FilePicker.platform.pickFiles(
dialogTitle: dialogTitle,
type: FileType.image,
);
final file = res?.files.firstOrNull;
if (file == null || (file.path == null && file.bytes == null)) {
throw Exception("File not found.");
}
return PickerValue(path: file.path, bytes: file.bytes);
case PickerFileType.video:
final res = await FilePicker.platform.pickFiles(
dialogTitle: dialogTitle,
type: FileType.video,
);
final file = res?.files.firstOrNull;
if (file == null || (file.path == null && file.bytes == null)) {
throw Exception("File not found.");
}
return PickerValue(path: file.path, bytes: file.bytes);
default:
final res = await FilePicker.platform.pickFiles(
dialogTitle: dialogTitle,
);
final file = res?.files.firstOrNull;
if (file == null || (file.path == null && file.bytes == null)) {
throw Exception("File not found.");
}
return PickerValue(path: file.path, bytes: file.bytes);
}
}