-
Notifications
You must be signed in to change notification settings - Fork 674
API
All the paths can be filtered using one of the following enumerations:
Filter | Description |
---|---|
FileType.any |
Will let you pick all available files. |
FileType.custom |
Will let you pick a path for the extension matching the allowedExtensions provided. |
FileType.image |
Will let you pick an image file. Opens gallery (Photos app) on iOS. |
FileType.video |
Will let you pick a video file. Opens gallery (Photos app) on iOS. |
FileType.media |
Will let you pick either video or images. Opens gallery (Photos app) on iOS. |
FileType.audio |
Will let you pick an audio file. Opens music on iOS. Note that DRM protected files won't provide a path, null will be returned instead.
|
There are a few common parameters that all picking methods support, those are listed below:
Parameter | Type | Description | Default |
---|---|---|---|
type | FileType |
Defines the type of the filtered files. | FileType.any |
allowedExtensions | List<String> |
Accepts a list of allowed extensions to be filtered. Eg. [.pdf, .jpg]
|
- |
allowCompression | bool |
Defines whether image and/or video files should be compressed automatically by OS when picked. On Android has no effect as it always returns the original or integral file copy. | true |
withData | bool |
Sets if the file should be immediately loaded into memory and available as Uint8List on its PlatformFile instance. |
true on Web, false everywhere else |
onFileLoading | Function(FilePickerStatus) |
When provided, will receive the processing status of picked files. This is particularly useful if you want to display a loading dialog or so when files are being downloaded/cached | - |
This is the main method to pick files and provides all the properties mentioned before. Will return a FilePickerResult
— containing the List<PlatformFile>
> — or null
if picker is aborted.
NOTE: You must use
FileType.custom
when providingallowedExtensions
, else it will throw an exception.
NOTE 2: On web the
path
will always benull
as web always use fake paths, you should use thebytes
instead to retrieve the picked file data.
// Will let you pick one file path, from all extensions
FilePickerResult result = await FilePicker.platform.pickFiles(type: FileType.any);
if(result != null) {
File file = File(result.files.first.path);
}
// Will filter and only let you pick files with svg and pdf extension
FilePickerResult result = await FilePicker.platform.pickFiles(type: FileType.custom, allowedExtensions: ['svg', 'pdf']);
if(result != null) {
File file = File(result.files.first.path);
}
Will let you select and pick a directory path.
Platform | Result |
---|---|
iOS | Requires iOS 11 or above |
Android | Requires SDK 21 or above |
Desktop | - |
Web | Not supported |
An utility method that will explicitly prune cached files from the picker. This is not required as the system will take care on its own, however, sometimes you may want to remove them, specially if your app handles a lot of files.
Platform | Result |
---|---|
iOS | All picked files are cached, so this will immediately remove them. |
Android | Since 2.0.0, all picked files are cached, so this will immediately remove them. |
Desktop & Web | Not implemented as it won't have any effect. Paths are always referencing the original files. |