tree: 3ad28c8f44625732708bc5b320c1181e562de266 [path history] [tgz]
  1. example/
  2. lib/
  3. test/
  4. AUTHORS
  5. CHANGELOG.md
  6. LICENSE
  7. pubspec.yaml
  8. README.md
packages/file_selector/file_selector/README.md

file_selector

pub package

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

iOSLinuxmacOSWebWindows
SupportiOS 11+Any10.14+AnyWindows 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/>

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

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,
]);

Save a file

const String fileName = 'suggested_name.txt';
final String? path = await getSavePath(suggestedName: fileName);
if (path == 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(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.

iOSLinuxmacOSWebWindows
extensions✔️✔️✔️✔️
mimeTypes✔️✔️†✔️
uniformTypeIdentifiers✔️✔️
webWildCards✔️

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

Features supported by platform

FeatureDescriptioniOSLinuxmacOSWindowsWeb
Choose a single filePick a file/image✔️✔️✔️✔️✔️
Choose multiple filesPick multiple files/images✔️✔️✔️✔️✔️
Choose a save locationPick a directory to save a file in✔️✔️✔️
Choose a directoryPick a folder and get its path✔️✔️✔️