Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds support for retrieving file paths from gallery and camera due to… #2

Merged
merged 1 commit into from
Sep 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,36 @@ File picker plugin alows you to use a native file explorer to load absolute file

## Installation

First, add file_picker as a dependency in [your pubspec.yaml file](https://flutter.io/platform-plugins/).
First, add both *file_picker* and *image_picker* as dependency in [your pubspec.yaml file](https://flutter.io/platform-plugins/).

Note: for now, just add it as git plugin.
Note: for now, just add the file_picker as git plugin.
```
file_picker:
git:
url: https://github.com/miguelpruivo/plugins_flutter_file_picker.git

```

and the [image_picker](https://pub.dartlang.org/packages/image_picker#-readme-tab-).
```
image_picker: ^0.4.10
```

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

## iOS
No configuration required - the plugin should work out of the box.
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 & cloud<br>
[X] Load pdf files<br>
[X] Load paths from local files & cloud (GDrive, Dropbox, iCloud)<br>
[X] Load PDF file path<br>
[X] Load path from gallery<br>
[X] Load path from camera shot<br>
[ ] Load a custom format<br>

## Example
Expand Down
7 changes: 7 additions & 0 deletions example/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>

<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>NSCameraUsageDescription</key>
<string>Used to demonstrate image picker plugin</string>
<key>NSMicrophoneUsageDescription</key>
<string>Used to capture audio for image picker plugin</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Used to demonstrate image picker plugin</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
Expand Down
31 changes: 29 additions & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@ class MyApp extends StatefulWidget {
class _MyAppState extends State<MyApp> {
String _path = '...';
String _fileName = '...';
FileType _pickingType;

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

if (!mounted) return;

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

Expand All @@ -45,6 +46,32 @@ class _MyAppState extends State<MyApp> {
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(
Expand Down
28 changes: 27 additions & 1 deletion lib/file_picker.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,35 @@
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:meta/meta.dart';
import 'package:image_picker/image_picker.dart';

class FilePicker {
static const MethodChannel _channel = const MethodChannel('file_picker');

static Future<String> get getFilePath async => await _channel.invokeMethod('pickPDF');
static Future<String> get _getPDF async => await _channel.invokeMethod('pickPDF');

static Future<String> _getImage(ImageSource type) async {
var image = await ImagePicker.pickImage(source: type);

return image?.path;
}

static Future<String> getFilePath({@required FileType type}) async {
switch (type) {
case FileType.PDF:
return _getPDF;
case FileType.IMAGE:
return _getImage(ImageSource.gallery);
case FileType.CAPTURE:
return _getImage(ImageSource.camera);
}
return null;
}
}

enum FileType {
PDF,
IMAGE,
CAPTURE,
}
9 changes: 5 additions & 4 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
name: file_picker
description: A new flutter plugin project.
version: 0.0.1
author:
homepage:
description: A plugin that allows you to pick absolute paths from diferent file types.
version: 1.0.0
author: Miguel Ruivo
homepage: https://github.com/miguelpruivo/plugins_flutter_file_picker

dependencies:
flutter:
sdk: flutter
image_picker: ^0.4.10

environment:
sdk: '<3.0.0'
Expand Down