Skip to content
Miguel Ruivo edited this page Sep 11, 2020 · 49 revisions

Filters

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.

Parameters

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 -

Methods

pickFiles()

This is the main method to pick files and provides all the properties mentioned before. Will return a FilePickerResult or null if picker is aborted.

NOTE: You must use FileType.custom when providing allowedExtensions, else it will throw an exception.

Usage example

// 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);
}

getDirectoryPath()

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

clearTemporaryFiles()

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 Typically files picked from remote providers or local files which the path can't be handled otherwise.
Desktop & Web Not implemented as it won't have any effect. Paths are always referencing the original files.
Clone this wiki locally