Skip to content

File picker plugin for Flutter, compatible with both iOS & Android.

License

Notifications You must be signed in to change notification settings

tommaso1/plugins_flutter_file_picker

 
 

Repository files navigation

file_picker

File picker plugin alows you to use a native file explorer to load absolute file path from different types of files.

Installation

First, add file_picker as a dependency in your pubspec.yaml file.

file_picker: ^0.1.3

Android

Add <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> to your app AndroidManifest.xml file.

iOS

Since we are using image_picker as a dependency from this plugin to load paths from gallery and camera, we need the following keys to your Info.plist file, located in <project root>/ios/Runner/Info.plist:

  • NSPhotoLibraryUsageDescription - describe why your app needs permission for the photo library. This is called Privacy - Photo Library Usage Description in the visual editor.
  • NSCameraUsageDescription - describe why your app needs access to the camera. This is called Privacy - Camera Usage Description in the visual editor.
  • NSMicrophoneUsageDescription - describe why your app needs access to the microphone, if you intend to record videos. This is called Privacy - Microphone Usage Description in the visual editor.

To-do

  • Load paths from local files & cloud (GDrive, Dropbox, iCloud)
  • Load PDF file path
  • Load path from gallery
  • Load path from camera shot
  • Load a custom format

Demo App

Demo

Example

import 'package:file_picker/file_picker.dart';

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  String _filePath;

  void getFilePath() async {
   try {
      String filePath = await FilePicker.getFilePath(type: FileType.PDF);
      if (filePath == '') {
        return;
      }
      print("File path: " + filePath);
      setState((){this._filePath = filePath;});
    } on PlatformException catch (e) {
      print("Error while picking the file: " + e.toString());
    }
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('File Picker Example'),
      ),
      body: new Center(
        child: _filePath == null
            ? new Text('No file selected.')
            : new Text('Path' + _filePath),
      ),
      floatingActionButton: new FloatingActionButton(
        onPressed: getFilePath,
        tooltip: 'Select file',
        child: new Icon(Icons.sd_storage),
      ),
    );
  }
}

Getting Started

For help getting started with Flutter, view our online documentation.

For help on editing plugin code, view the documentation.

About

File picker plugin for Flutter, compatible with both iOS & Android.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 48.4%
  • Dart 19.6%
  • Objective-C 18.7%
  • Ruby 13.3%