pickFiles method
- String? dialogTitle,
- String? initialDirectory,
- FileType type = FileType.any,
- List<
String> ? allowedExtensions, - dynamic onFileLoading()?,
- bool allowCompression = true,
- int compressionQuality = 30,
- bool allowMultiple = false,
- bool withData = false,
- bool withReadStream = false,
- bool lockParentWindow = false,
- bool readSequential = false,
Retrieves the file(s) from the underlying platform
Default type
set to FileType.any with allowMultiple
set to false
.
Optionally, allowedExtensions
might be provided (e.g. [pdf, svg, jpg]
.).
If withData
is set, picked files will have its byte data immediately available on memory as Uint8List
which can be useful if you are picking it for server upload or similar. However, have in mind that
enabling this on IO (iOS & Android) may result in out of memory issues if you allow multiple picks or
pick huge files. Use withReadStream
instead. Defaults to true
on web, false
otherwise.
If withReadStream
is set, picked files will have its byte data available as a Stream<List<int>>
which can be useful for uploading and processing large files. Defaults to false
.
If you want to track picking status, for example, because some files may take some time to be
cached (particularly those picked from cloud providers), you may want to set onFileLoading
handler
that will give you the current status of picking.
If allowCompression
is set, it will allow media to apply the default OS compression.
Defaults to true
.
If lockParentWindow
is set, the child window (file picker window) will
stay in front of the Flutter window until it is closed (like a modal
window). This parameter works only on Windows desktop.
dialogTitle
can be optionally set on desktop platforms to set the modal window title. It will be ignored on
other platforms.
initialDirectory
can be optionally set to an absolute path to specify
where the dialog should open. Only supported on Linux, macOS, and Windows.
readSequential
can be optionally set on web to keep the import file order during import.
The result is wrapped in a FilePickerResult which contains helper getters with useful information regarding the picked List<PlatformFile>.
For more information, check the API documentation.
Returns null
if aborted.
Implementation
@override
Future<FilePickerResult?> pickFiles({
String? dialogTitle,
String? initialDirectory,
FileType type = FileType.any,
List<String>? allowedExtensions,
Function(FilePickerStatus)? onFileLoading,
bool allowCompression = true,
int compressionQuality = 30,
bool allowMultiple = false,
bool withData = false,
bool withReadStream = false,
bool lockParentWindow = false,
bool readSequential = false,
}) async {
final String executable = await isExecutableOnPath('osascript');
final String fileFilter = fileTypeToFileFilter(
type,
allowedExtensions,
);
final List<String> arguments = generateCommandLineArguments(
escapeDialogTitle(dialogTitle ?? defaultDialogTitle),
fileFilter: fileFilter,
initialDirectory: initialDirectory ?? '',
multipleFiles: allowMultiple,
pickDirectory: false,
);
final String? fileSelectionResult = await runExecutableWithArguments(
executable,
arguments,
);
if (fileSelectionResult == null) {
return null;
}
final List<String> filePaths = resultStringToFilePaths(
fileSelectionResult,
);
final List<PlatformFile> platformFiles = await filePathsToPlatformFiles(
filePaths,
withReadStream,
withData,
);
return FilePickerResult(platformFiles);
}