A Flutter plugin to select, open, choose, pick and create documents, images videos

Overview

file_picker_cross

The only Flutter plugin to select, open, choose, pick and create documents, images videos or other files on Android, iOS, the desktop and the web for reading, writing, use as String, byte list or HTTP uploads.

Getting Started

file_picker_cross allows you to select, edit and save files from your device and is compatible with Android, iOS, Desktops (using both go-flutter or FDE) and the web.

Note: we recently had API changes. Please update your code accordingly.

myMultipleFiles = await FilePickerCross.importMultipleFromStorage(); print(myMultipleFiles); // list all previously opened files List paths = await FilePickerCross.listInternalFiles(); print(paths); // open an existing file FilePickerCross anotherFile = FilePickerCross.fromInternalPath(paths[0]); // delete our perfect file FilePickerCross.delete(paths[0]); // get the file storage size print(await FilePickerCross.quota()); // you can access the following properties on a FilePickerCross instance: myFile.toString(); myFile.toUint8List(); myFile.toBase64(); myFile.toMultipartFile(filename: 'myFile.txt'); myFile.length; myFile.path; myFile.fileName; myFile.fileExtension; myFile.directory; ">
// show a dialog to open a file
FilePickerCross myFile = await FilePickerCross.importFromStorage(
  type: FileTypeCross.any,       // Available: `any`, `audio`, `image`, `video`, `custom`. Note: not available using FDE
  fileExtension: 'txt, md'     // Only if FileTypeCross.custom . May be any file extension like `dot`, `ppt,pptx,odp`
);

// save our file to the fictional directory. It is not necessary that it already exists.
myFile.saveToPath('/my/awesome/folder/' + myFile.fileName);

// save our file to the internal storage or share to other apps
myFile.exportToStorage();

// for sharing to other apps you can also specify optional `text` and `subject`
myFile.exportToStorage(
  subject: "Awesome file",
  text: "Here is the file you've been waiting for",
);

// on iPad you may also need to specify the `sharePositionOrigin` for native share UI
GlobalKey widgetKey = GlobalKey();
...
RenderBox renderBox = widgetKey.currentContext.findRenderObject();
Offset position = renderBox.localToGlobal(Offset.zero);
filePickerCross.exportToStorage(
    position.dx, position.dy, renderBox.size.width, renderBox.size.height);

List<FilePickerCross> myMultipleFiles = await FilePickerCross.importMultipleFromStorage();
print(myMultipleFiles);

// list all previously opened files
List<String> paths = await FilePickerCross.listInternalFiles();
print(paths);

// open an existing file
FilePickerCross anotherFile = FilePickerCross.fromInternalPath(paths[0]);

// delete our perfect file
FilePickerCross.delete(paths[0]);

// get the file storage size
print(await FilePickerCross.quota());

// you can access the following properties on a FilePickerCross instance:

myFile.toString();

myFile.toUint8List();

myFile.toBase64();

myFile.toMultipartFile(filename: 'myFile.txt');

myFile.length;

myFile.path;

myFile.fileName;

myFile.fileExtension;

myFile.directory;

To get details about the certain properties and methods, check out the API documentation.

Exception handling

Different platforms will throw different exceptions whether it is due to user action or platform restrictions. For instance, you may want to know if a user had denied access to storage and act upon it. There is a method to help out with that.

await FilePickerCross.importFromStorage().then(() {
  // ...
}).onError((error, _) {
  String _exceptionData = error.reason();
  print('----------------------');
  print('REASON: ${_exceptionData}');
  if (_exceptionData == 'read_external_storage_denied') {
    print('Permission was denied');
  } else if (_exceptionData == 'selection_canceled') {
    print('User canceled operation');
  } 
  print('----------------------');
});

When the FileSelectionCanceledError exception is thrown, you can access the reason() method to collect underlying exception information. It has a return type of String.

Behavior:

  • On user cancelation, selection_canceled is returned
  • When PlatformException exception occurs, the raw error value is extracted and then returned (i.e. read_external_storage_denied)
  • As a fallback, exceptions that were not 'handled' will be returned in full

The scope of this package

TL;DR: We provide a parallel, platform-independent implementation of a fake file system, in which you can create, open and save files for your app - even on the web. Moreover, we provide APIs to interact with the real file system as well to import and export files from and to your device.

It is very difficult to handle files in cross platform apps. While desktops have one files system used for all apps, mobile platforms have isolated file systems for each app. The web does not really have a working file system available on all browsers. Hence, it is hard to implement storage and access to files on all platforms - and you do not have to because we already did this for you.

With file_picker_cross, we provide a fake file system for use in your app. Unlike other packages, we do not only provide a dialog for reading or saving files, but we provide a whole file system inside your app's storage, in which you can use any operation like searching files, opening them and saving them. Of cause, there are APIs too for importing files from the shared storage (device storage, home folder, etc.) or exporting to these - even on the web.

Where files are saved

There are two important methods to export/save files: exportToStorage and saveToPath.

  • exportToStorage shows a dialog and allows the user to select where to save the file.
  • saveToPath is meant for automated saving in case files are automatically created by an application for further use only within the application. For the web, it means, files are stored in the localStorage, on Windows, the path is %LOCALAPPDATA%\your_app_name\ and on all other platforms the files are stored in ${getApplicationDocumentsDirectory()}/your_app_name/.

A word on directories

Why is isn't it possible to pick directories? That's what we are asked commonly. There is a simple reason: mobile and web device's security mechanisms.

Anyway, there are two workarounds available, depending on what you plan to do.

If you have plenty of files, you simply need to store somewhere, you may use our provided saveToPath('/my/path') API. This allows you to save any file to an app-internal path. See the API documentation for further details.

Another use case is saving files to a user-defined directory. For single files, you may use the exportToStorage() API (documentation). But if you want to once pick a directory and save continuously save and read files there, it will generally be impossible on most devices except of desktops. All other device types prevent this by their security mechanisms. On desktops (and unfortunately only on desktops), there is a workaround available:

// for the first file, you show an export as dialog
FilePickerCross myFile = ...

String pathForExports = await myFile.exportToStorage(); // <- will return the file's path on desktops

// you parse the file's directory and use it for later automated exports.
pathForExports = pathForExports.substring(0,pathForExports.lastIndexOf(r'/'));
print(pathForExports);

// now save the path for later use using shared preferences etc.
...

// next time, check whether you are overwriting an existing file or simply write the file
print(await File(pathForExports+'/myNextFile.csv').exists());
File myCsvFile = await File(pathForExports+'/myNextFile.csv').writeAsString('comma,separated,values'); // <- This only works on desktops. All other devices prevent this.

(Source: Issue #11)

Moreover, we plan to support direct write access on certain shared storage locations of the device like Documents, Downloads etc. Our plans on that as well as the API are not ready yet but you might expect this to be supported.

go-flutter and FDE

Flutter initially only supported Android and iOS. To add support for desktop platforms, some people started the go-flutter providing Flutter applications on Windows, Linux and macOS using the Go language.

Later, Flutter itself announced desktop support (FDE) but still, it's not stable yet.

We try to support both as much as possible.

Web

Of cause, it requires Flutter to be set up for web development.

Set up Flutter for Web

All Desktop platforms

Of cause, it requires Flutter to be set up for your platform.

Please note, Windows is not officially supported by Google. Linux and macOS support is in alpha state. Expect issues and sometimes incompatible versions requiring manual hand work.

flutter channel dev # or master
flutter upgrade
flutter config --enable-linux-desktop
flutter config --enable-macos-desktop
flutter config --enable-windows-desktop

More information

Set up go-flutter or Set up FDE

Mobile platforms

No setup required 🎉 .

macOS (using FDE)

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

 
   
    com.apple.security.files.user-selected.read-only
   
 
   

or read/write access:

 
   
    com.apple.security.files.user-selected.read-write
   
 
   

depending on your use case.

Linux (using FDE)

This plugin requires the following libraries:

  • GTK 3
  • pkg-config
  • xdg-user-dirs

Installation example for Debian-based systems:

sudo apt-get install libgtk-3-dev pkg-config xdg-user-dirs

Note: You do no longer have to modify any files unlike in previous versions.

You might also like...

Flutter based Open Source Hentai Viewer App

Flutter based  Open Source Hentai Viewer App

Flutter based Open Source Hentai Viewer App

Jan 2, 2023

Simple tool to open WhatsApp chat without saving the number, developed using Google's Flutter Framework.

Simple tool to open WhatsApp chat without saving the number, developed using Google's Flutter Framework.

Simple tool to open WhatsApp chat without saving the number, developed using Google's Flutter Framework. for Android/ IOS/ Desktop/ Web

Nov 1, 2022

An open source Github client App developed by Flutter

An open source Github client App developed by Flutter

English Readme 一款跨平台的开源Github客户端App,提供更丰富的功能,更好体验,旨在更好的日常管理和维护个人Github,

Dec 31, 2022

Google UI is an open-source UI library for developing cross-platform apps using Flutter with Material Design 2.0

Google UI is an open-source UI library for developing cross-platform apps using Flutter with Material Design 2.0

Google UI Google UI is an open-source UI library for developing cross-platform apps using Flutter with "Material Design 2.0" Table of contents Install

Dec 24, 2022

Open source code for Bonfire flutter app

Open source code for Bonfire flutter app

Open source code for Bonfire flutter app

Nov 15, 2022

Example functions to show off what you can achieve with Open Runtimes

Example functions to show off what you can achieve with Open Runtimes

Open Runtimes Functions Examples ⚡️ Example functions to show off what you can achieve with Open Runtimes. List of Examples Example Dart Deno Node PHP

Jan 6, 2023

Use dynamic and beautiful card view pagers (horizontal direction) to help you create great apps.

Use dynamic and beautiful card view pagers (horizontal direction) to help you create great apps.

Use dynamic and beautiful card view pagers (horizontal direction) to help you create great apps. Preview Mobile Vertical Card Pager Web Web Link Insta

Dec 9, 2022

TutorialCoachMark - Create a beautiful and easy tutorial for your application.

TutorialCoachMark - Create a beautiful and easy tutorial for your application.

TutorialCoachMark Create a beautiful and easy tutorial for your application. Example 1 Example 2 Usage To use this plugin, add tutorial_coach_mark as

Dec 25, 2022

Flutter social button - A flutter package to create social media login buttons easily to any flutter app

Flutter social button - A flutter package to create social media login buttons easily to any flutter app

Flutter Social Button is a flutter package to create social media login buttons easily to any flutter app.

Dec 5, 2022
Owner
null
This app it's a simple app to help you choose between alcool or gasoline based on the price of the gasoline and the price of the alcool.

This app it's a simple app to help you choose between alcool or gasoline based on the price of the gasoline and the price of the alcool. It's a simple app that uses a simple logo, two text fields and a button that calculate and show the best option.

Cácio Lucas 0 Oct 3, 2021
How to click, pick, crop and compress an image

flutter_click_pick_crop_compress A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to

Pawan Kumar 39 Jan 18, 2022
Flutter File Select and Upload to the Server with Progress Bar - Day 44

Flutter File Select and Upload - Day 44 class Afgprogrammer extends Flutter100DaysOfCode { video() { return { "title": "Flutter File Selec

Mohammad Rahmani 30 Dec 17, 2022
FTFS is a Flutter package which uses a TextField Widget to search and select a value from a list

FTFS is a Flutter package which uses a TextField Widget to search and select a value from a list. It's a simple, lightweight, and fully tested package unlike other "autocomplete" or textfield search packages.

null 1 Jan 5, 2022
Flutter Music Player - First Open Source Flutter based material design music player with audio plugin to play local music files.

Flutter Music Player First Open Source Flutter based Beautiful Material Design Music Player(Online Radio will be added soon.) Demo App Play Store BETA

Pawan Kumar 1.5k Jan 2, 2023
Flute Music Player - First Open Source Flutter based material design music player with audio plugin to play local music files.

Flute Music Player Plugin Only Updated to androidx First Open Source Flutter based material design music player with audio plugin to play local music

Pawan Kumar 316 Nov 23, 2022
Minimal Unsplash Android App to easily search, explore and download images using Unsplash API.

Minimal Unsplash Android App to easily search, explore and download images using Unsplash API. Download Button to download the image. User can set the image as a wallpaper. There is a favorite icon, which user can tap to mark/un-mark that image as a favorite.

derpLLC 1 Mar 27, 2022
a simple Quran app made with flutter without any images or pdf

forqan A simple Quran app made with flutter without any images or pdf . screenshot Support If you like what we do, and would want to help us continue

null 15 Oct 22, 2022
Create an Invoice PDF Document completely with Flutter and learn how to generate and view this invoice in Flutter.

Create an Invoice PDF Document completely with Flutter and learn how to generate and view this invoice in Flutter.

Johannes Milke 124 Jan 4, 2023
Flutter project integrated with Supabase, the Firebase open source alternative

This is a Flutter project integrated with Supabase, the Firebase open source alternative. This project is a sandbox for playground for Flutter & Supabase integration.

anegrete 13 Oct 18, 2022