file_selector 1.0.3 copy "file_selector: ^1.0.3" to clipboard
file_selector: ^1.0.3 copied to clipboard

Flutter plugin for opening and saving files, or selecting directories, using native file selection UI.

file_selector #

pub package

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

Android iOS Linux macOS Web Windows
Support SDK 19+ iOS 12+ Any 10.14+ Any Windows 10+

Usage #

To use this plugin, add file_selector as a dependency in your pubspec.yaml file.

macOS #

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

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

or read/write access:

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

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 XTypeGroup typeGroup = XTypeGroup(
  label: 'images',
  extensions: <String>['jpg', 'png'],
);
final XFile? file =
    await openFile(acceptedTypeGroups: <XTypeGroup>[typeGroup]);
copied to clipboard

Open multiple files at once

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

Save a file

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

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

Get a directory path

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

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.

Andoid iOS Linux macOS Web Windows
extensions ✔️ ✔️ ✔️ ✔️ ✔️
mimeTypes ✔️ ✔️ ✔️† ✔️
uniformTypeIdentifiers ✔️ ✔️
webWildCards ✔️

mimeTypes are not supported on version of macOS earlier than 11 (Big Sur).

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 ✔️† ✔️ ✔️ ✔️

† Choosing a directory is no supported on versions of Android before SDK 21 (Lollipop).

395
likes
160
points
164k
downloads

Publisher

verified publisherflutter.dev

Weekly Downloads

2024.09.08 - 2025.03.23

Flutter plugin for opening and saving files, or selecting directories, using native file selection UI.

Repository (GitHub)
View/report issues
Contributing

Topics

#files #file-selection #file-selector

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

file_selector_android, file_selector_ios, file_selector_linux, file_selector_macos, file_selector_platform_interface, file_selector_web, file_selector_windows, flutter

More

Packages that depend on file_selector