Giter Club home page Giter Club logo

flutter_file_picker_desktop's Introduction

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 three things:

  • picking files
  • picking directories
  • saving files

โš ๏ธ PLEASE NOTE:

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.

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.
  • ๐Ÿ’ฟ 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.

โš ๏ธ 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 File Picker Linux Directory Picker Linux Save File Dialog
Select file on Linux Select directory on Linux Save file on Linux
macOS File Picker macOS Directory Picker macOS Save File Dialog
Select file on macOS Select directory on macOS Save file on macOS
Windows Windows Directory Picker Windows Save File Dialog
Select file on Windows Select directory on Windows Save file on Windows

Usage

Add package to pubspec.yaml:

dependencies:
  file_picker_desktop: ^1.1.1

Import:

import 'package:file_picker_desktop/file_picker_desktop.dart';

Dialog for picking a 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);
}

Dialog for picking 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);
}

Dialog for picking multiple files with extension filter:

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

Load the results 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
}

Dialog for picking a directory:

try {
  final selectedDirectory = await getDirectoryPath();
  if (selectedDirectory != null) {
    File directory = File(selectedDirectory);
  } else {
    // User canceled the picker
  }
} catch (e) {
  print(e);
}

Dialog for saving a file:

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

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

flutter_file_picker_desktop's People

Contributors

philenius avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

f69

flutter_file_picker_desktop's Issues

macOS user experience (UX) feedback

Hello, the file chooser can be used normally on macOS, but it has a bad experience: opening the view does not immediately get the focus, I need to click on the view to get the focus

Cannot open file in MacOS

This is the error:
FileSystemException: Cannot retrieve length of file, path = '/Projects/VXX/json.json' (OS Error: No such file or directory, errno = 2)

Same code works well in Windows. Only happen in MacOS.
What did I miss?
Hope to hear from you soon.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.