Coder Social home page Coder Social logo

vadpinchuk / plugins_flutter_file_picker Goto Github PK

View Code? Open in Web Editor NEW

This project forked from miguelpruivo/flutter_file_picker

0.0 2.0 0.0 9.59 MB

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

License: MIT License

Java 45.64% Ruby 9.27% Objective-C 21.32% Dart 23.76%

plugins_flutter_file_picker's Introduction

pub package Awesome Flutter

file_picker

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

Installation

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

file_picker: ^1.1.1

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.
  • UIBackgroundModes with the fetch and remote-notifications keys - describe why your app needs to access background taks, such downloading files (from cloud services) when not cached to locate path. This is called Required background modes, with the keys App download content from network and App downloads content in response to push notifications respectively in the visual editor (since both methods aren't actually overriden, not adding this property/keys may only display a warning, but shouldn't prevent its correct usage).

Usage

There's only one method within this package FilePicker.getFilePath() this receives 2 optional parameters, the fileType and a fileExtension to be used along with FileType.CUSTOM. So, 2 basically usages may be:

await FilePicker.getFilePath(type: FileType.ANY); // will display all file types
await FilePicker.getFilePath(type: FileType.CUSTOM, fileExtension: 'svg'); // will filter and display only files with SVG extension.

Note: When using FileType.CUSTOM, unsupported extensions will throw a MissingPluginException that is handled by the plugin.

Currently supported features

  • Load paths from cloud files (GDrive, Dropbox, iCloud)
  • Load path from gallery
  • Load path from camera
  • Load path from video
  • Load path from any type of file (without filtering)
  • Load path from a custom format by providing a file extension (pdf, svg, zip, etc.)

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.ANY);
      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.

plugins_flutter_file_picker's People

Contributors

vadympinchuk avatar

Watchers

 avatar  avatar

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.