file_picker_desktop 1.0.0 copy "file_picker_desktop: ^1.0.0" to clipboard
file_picker_desktop: ^1.0.0 copied to clipboard

discontinuedreplaced by: file_picker
outdated

A package that allows you to use a native file explorer on Windows, macOS, and Linux to pick a directory or one or multiple files, with extension filtering support.

File Picker Desktop #

CI Pipeline

This repository contains a Dart package that allows you to use a native file explorer on Windows, macOS, and Linux for picking files and directories.

Features #

  • 🎉 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.
  • 🔧 Different filtering options for file types included (+ customizable).
  • 🎉 Customizable title of the file picker dialog.
  • 🤖 Runs on Linux, macOS, and Windows.

⚠️ This package does not support Android, iOS, or the web. Please refer to Miguel Pruivo's package github.com/miguelpruivo/flutter_file_picker which offers the same functionality for Android, iOS, and the web. I tried my best to provide the same API as Miguel's package.

The following screenshots show the file picker dialog on Linux, macOS, and Windows:

Linux
Select file on Linux Select directory on Linux
macOS
Select file on macOS Select directory on macOS
Windows
Select file on Windows Select directory on Windows

Usage #

Add to package to pubspec.yaml: #

...

dependencies:
  file_picker_desktop: ^1.0.0-dev.1

Import: #

import 'package:file_picker_desktop/file_picker_desktop.dart';

Single File: #

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

Multiple files: #

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

Multiple files with extension filter: #

final result = await pickFiles(
  allowMultiple: true,
  type: FileType.custom,
  allowedExtensions: ['jpg', 'pdf', 'doc'],
);

Load result and file details: #

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
}

Example Flutter App #

Demo Flutter App

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
18
likes
0
pub points
61%
popularity

Publisher

unverified uploader

A package that allows you to use a native file explorer on Windows, macOS, and Linux to pick a directory or one or multiple files, with extension filtering support.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

ffi, path

More

Packages that depend on file_picker_desktop