file_picker 0.1.6

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 94

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

  • [X] Load paths from local files & cloud (GDrive, Dropbox, iCloud)
  • [X] Load PDF file path
  • [X] Load path from gallery
  • [X] 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.

0.1.6

  • Replaces commons dependency with FilePath class on Android, to handle path resolution on different SDK.

0.1.5

  • Minor correction on README file.

0.1.4

  • Changed Meta minimum version due to versioning conflict with flutter_localization.

0.1.3

  • Updated readme.

0.1.2

  • Changed license from Apache 2.0 to MIT.
  • Adds demo screenshot.

0.1.1

  • Adds license information (Apache 2.0).
  • Adds CHANGELOG details.

0.1.0

  • Initial realise.
  • Supports picking paths from files on local storage, cloud.
  • Supports picking paths from both gallery & camera due to image_picker dependency.

example/lib/main.dart

import 'package:flutter/material.dart';

import 'package:flutter/services.dart';
import 'package:file_picker/file_picker.dart';

void main() => runApp(new MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _path = '...';
  String _fileName = '...';
  FileType _pickingType;

  void _openFileExplorer() async {
    try {
      _path = await FilePicker.getFilePath(type: _pickingType);
    } on PlatformException catch (e) {
      print(e.toString());
    }

    if (!mounted) return;

    setState(() {
      _fileName = _path != null ? _path.split('/').last : '...';
    });
  }

  // Platform messages are asynchronous, so we initialize in an async method.

  // If the widget was removed from the tree while the asynchronous platform
  // message was in flight, we want to discard the reply rather than calling
  // setState to update our non-existent appearance.

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: const Text('Plugin example app'),
        ),
        body: new Center(
            child: new Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            new Padding(
              padding: const EdgeInsets.all(20.0),
              child: new DropdownButton(
                hint: new Text('LOAD FILE PATH FROM...'),
                value: _pickingType,
                items: <DropdownMenuItem>[
                  new DropdownMenuItem(
                    child: new Text('FROM CAMERA'),
                    value: FileType.CAPTURE,
                  ),
                  new DropdownMenuItem(
                    child: new Text('FROM GALLERY'),
                    value: FileType.IMAGE,
                  ),
                  new DropdownMenuItem(
                    child: new Text('FROM PDF'),
                    value: FileType.PDF,
                  )
                ],
                onChanged: (value) {
                  setState(() {
                    _pickingType = value;
                  });
                },
              ),
            ),
            new Padding(
              padding: const EdgeInsets.all(20.0),
              child: new RaisedButton(
                onPressed: () => _openFileExplorer(),
                child: new Text("Open file picker"),
              ),
            ),
            new Text(
              'URI PATH ',
              textAlign: TextAlign.center,
              style: new TextStyle(fontWeight: FontWeight.bold),
            ),
            new Text(
              _path,
              textAlign: TextAlign.center,
              softWrap: true,
              textScaleFactor: 0.85,
            ),
            new Padding(
              padding: const EdgeInsets.only(top: 10.0),
              child: new Text(
                'FILE NAME ',
                textAlign: TextAlign.center,
                style: new TextStyle(fontWeight: FontWeight.bold),
              ),
            ),
            new Text(
              _fileName,
              textAlign: TextAlign.center,
            ),
          ],
        )),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  file_picker: ^0.1.6

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:file_picker/file_picker.dart';
  
Version Uploaded Documentation Archive
0.1.6 Sep 12, 2018 Go to the documentation of file_picker 0.1.6 Download file_picker 0.1.6 archive
0.1.5 Sep 11, 2018 Go to the documentation of file_picker 0.1.5 Download file_picker 0.1.5 archive
0.1.4 Sep 11, 2018 Go to the documentation of file_picker 0.1.4 Download file_picker 0.1.4 archive
0.1.3 Sep 10, 2018 Go to the documentation of file_picker 0.1.3 Download file_picker 0.1.3 archive
0.1.2 Sep 10, 2018 Go to the documentation of file_picker 0.1.2 Download file_picker 0.1.2 archive
0.1.1 Sep 10, 2018 Go to the documentation of file_picker 0.1.1 Download file_picker 0.1.1 archive
0.1.0 Sep 9, 2018 Go to the documentation of file_picker 0.1.0 Download file_picker 0.1.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
87
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
94
Learn more about scoring.

We analyzed this package on Nov 14, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.6
  • Flutter: 0.11.3

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.19.0 <3.0.0
flutter 0.0.0
image_picker ^0.4.10 0.4.10
meta ^1.1.5 1.1.6
Transitive dependencies
collection 1.14.11
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8