This repository contains a Dart package that allows you to use a native file explorer on Windows, macOS, and Linux for three things:
- picking files
- picking directories
- saving files
This Dart package has been archived in favor of file_picker by Miguel Pruivo (github.com/miguelpruivo/flutter_file_picker). All code of this repository has been integrated into Miguel's package. I recommend you to use his package, as I will only provide bug fixes, but will not add any additional features. Starting from version 4.0.0 Miguel's package can be used without Go/Go Flutter, too. Thank you.
- 🎉 This package does not require Go Flutter. This package is written entirely in Dart!!! No dependencies on Go or Go Flutter.
- 💾 Simple API for picking a single file or multiple files with support for filtering the allowed file extensions.
- 📁 Simple API for picking a directory.
- 💿 Simple API for saving a file.
- 🔧 Different filtering options for file types included (+ customizable).
- 🎉 Customizable title of the dialog.
- 🤖 Runs on Linux, macOS, and Windows.
The following screenshots show the file picker dialog on Linux, macOS, and Windows:
Linux File Picker | Linux Directory Picker | Linux Save File Dialog |
---|---|---|
macOS File Picker | macOS Directory Picker | macOS Save File Dialog |
Windows | Windows Directory Picker | Windows Save File Dialog |
dependencies:
file_picker_desktop: ^1.1.1
import 'package:file_picker_desktop/file_picker_desktop.dart';
try {
final result = await pickFiles(
allowMultiple: false,
);
if (result != null) {
File file = File(result.files.single.path);
} else {
// User canceled the picker
}
} catch (e) {
print(e);
}
try {
final result = await pickFiles(
allowMultiple: true,
);
if (result != null) {
List<File> files = result.paths
.where((path) => path != null)
.map((path) => File(path!))
.toList();
} else {
// User canceled the picker
}
} catch (e) {
print(e);
}
final result = await pickFiles(
allowMultiple: true,
type: FileType.custom,
allowedExtensions: ['jpg', 'pdf', 'doc'],
);
FilePickerResult? result = await pickFiles();
if (result != null) {
PlatformFile file = result.files.first;
print(file.name);
print(file.bytes);
print(file.size);
print(file.extension);
print(file.path);
} else {
// User canceled the picker
}
try {
final selectedDirectory = await getDirectoryPath();
if (selectedDirectory != null) {
File directory = File(selectedDirectory);
} else {
// User canceled the picker
}
} catch (e) {
print(e);
}
try {
final String? selectedFileName = await saveFile(
defaultFileName: 'default-file.txt',
);
if (selectedFileName != null) {
File file = File(selectedFileName);
} else {
// User canceled the picker
}
} catch (e) {
print(e);
}
The directory ./example/
contains an example Flutter app which showcases the file picker's functionality. You can run this example app the following way:
cd ./example/
flutter create .
# Choose the appropriate option depending on your OS
flutter config --enable-linux-desktop
flutter config --enable-macos-desktop
flutter config --enable-windows-desktop
flutter run