A Flutter plugin for iOS and Android for picking images from the image library, and taking new pictures with the camera.
Note: This plugin is still under development, and some APIs might not be available yet. Feedback welcome and Pull Requests are most welcome!
First, add image_picker
as a dependency in your pubspec.yaml file.
Add 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.No configuration required - the plugin should work out of the box.
import 'package:image_picker/image_picker.dart';
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
File _image;
Future getImage() async {
var image = await ImagePicker.pickImage(source: ImageSource.camera);
setState(() {
_image = image;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Image Picker Example'),
),
body: Center(
child: _image == null
? Text('No image selected.')
: Image.file(_image),
),
floatingActionButton: FloatingActionButton(
onPressed: getImage,
tooltip: 'Pick Image',
child: Icon(Icons.add_a_photo),
),
);
}
}
api
to define support-v4
dependency to allow automatic version resolution.support-v4
library for ease of use (fixes conflicts with Firebase and libraries)com.android.support:appcompat-v7
dependency with com.android.support:support-core-utils
, which results in smaller APK sizes.pickVideo
method will now return null when the user cancels picking a video.pickImage
method will now return null when the user cancels picking the image, instead of hanging indefinitely.source
parameter for the pickImage
is now required. Also, the ImageSource.any
option doesn't exist anymore.ImageSource.camera
.android/build.gradle
. For example:allprojects {
repositories {
jcenter()
maven { // NEW
url "https://maven.google.com" // NEW
} // NEW
}
}
example/README.md
Demonstrates how to use the image_picker plugin.
For help getting started with Flutter, view our online documentation.
Add this to your package's pubspec.yaml file:
dependencies:
image_picker: ^0.4.12+1
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.
Now in your Dart code, you can use:
import 'package:image_picker/image_picker.dart';
Version | Uploaded | Documentation | Archive |
---|---|---|---|
0.5.0+3 | Feb 8, 2019 |
|
|
0.5.0+2 | Feb 8, 2019 |
|
|
0.5.0+1 | Jan 31, 2019 |
|
|
0.5.0 | Jan 24, 2019 |
|
|
0.4.12+1 | Jan 18, 2019 |
|
|
0.4.12 | Jan 10, 2019 |
|
|
0.4.10 | Aug 30, 2018 |
|
|
0.4.8 | Aug 28, 2018 |
|
|
0.4.7 | Aug 21, 2018 |
|
|
0.4.6 | Jul 26, 2018 |
|
|
Popularity:
Describes how popular the package is relative to other packages.
[more]
|
100
|
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]
|
100
|
We analyzed this package on Feb 14, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:
Detected platforms: Flutter
References Flutter, and has no conflicting libraries.
Package | Constraint | Resolved | Available |
---|---|---|---|
Direct dependencies | |||
Dart SDK | >=2.0.0-dev.28.0 <3.0.0 | ||
flutter | 0.0.0 | ||
Transitive dependencies | |||
collection | 1.14.11 | ||
meta | 1.1.6 | 1.1.7 | |
sky_engine | 0.0.99 | ||
typed_data | 1.1.6 | ||
vector_math | 2.0.8 | ||
Dev dependencies | |||
flutter_test | |||
video_player | 0.5.2 |