Skip to content

Latest commit

 

History

History

file_selector

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

file_selector

pub package

A Flutter plugin that manages files and interactions with file dialogs.

Android iOS Linux macOS Web Windows
Support SDK 24+ iOS 15+ Any 12+ Any Windows 10+

Setup

macOS

You will need to add an entitlement for either read-only access:

  <key>com.apple.security.files.user-selected.read-only</key>
  <true/>

or read/write access:

  <key>com.apple.security.files.user-selected.read-write</key>
  <true/>

depending on your use case.

Examples

Here are small examples that show you how to use the API. Please also take a look at our example app.

Open a single file

const typeGroup = XTypeGroup(
  label: 'images',
  extensions: <String>['jpg', 'png'],
  uniformTypeIdentifiers: <String>['public.jpeg', 'public.png'],
);
final XFile? file = await openFile(acceptedTypeGroups: <XTypeGroup>[typeGroup]);

Open multiple files at once

const jpgsTypeGroup = XTypeGroup(
  label: 'JPEGs',
  extensions: <String>['jpg', 'jpeg'],
  uniformTypeIdentifiers: <String>['public.jpeg'],
);
const pngTypeGroup = XTypeGroup(
  label: 'PNGs',
  extensions: <String>['png'],
  uniformTypeIdentifiers: <String>['public.png'],
);
final List<XFile> files = await openFiles(
  acceptedTypeGroups: <XTypeGroup>[jpgsTypeGroup, pngTypeGroup],
);

Save a file

const fileName = 'suggested_name.txt';
final FileSaveLocation? result = await getSaveLocation(suggestedName: fileName);
if (result == null) {
  // Operation was canceled by the user.
  return;
}

final fileData = Uint8List.fromList('Hello World!'.codeUnits);
const mimeType = 'text/plain';
final textFile = XFile.fromData(fileData, mimeType: mimeType, name: fileName);
await textFile.saveTo(result.path);

Get a directory path

final String? directoryPath = await getDirectoryPath();
if (directoryPath == null) {
  // Operation was canceled by the user.
  return;
}

Filtering by file types

Different platforms support different type group filter options. To avoid ArgumentErrors on some platforms, ensure that any XTypeGroups you pass set filters that cover all platforms you are targeting, or that you conditionally pass different XTypeGroups based on Platform.

Android iOS Linux macOS Web Windows
extensions ✔️ ✔️ ✔️ ✔️ ✔️
mimeTypes ✔️ ✔️ ✔️ ✔️
uniformTypeIdentifiers ✔️ ✔️
webWildCards ✔️

Features supported by platform

Feature Description Android iOS Linux macOS Windows Web
Choose a single file Pick a file/image ✔️ ✔️ ✔️ ✔️ ✔️ ✔️
Choose multiple files Pick multiple files/images ✔️ ✔️ ✔️ ✔️ ✔️ ✔️
Choose a save location Pick a directory to save a file in ❌ ❌ ✔️ ✔️ ✔️ ❌
Choose a directory Pick a directory and get its path ✔️ ❌ ✔️ ✔️ ✔️ ❌