Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
[image_picker] add requestFullMetadata for iOS (optional permissions) (
Browse files Browse the repository at this point in the history
  • Loading branch information
PiotrMitkowski authored Oct 5, 2022
1 parent 3a928b8 commit fb5c86c
Show file tree
Hide file tree
Showing 7 changed files with 386 additions and 69 deletions.
3 changes: 2 additions & 1 deletion packages/image_picker/image_picker/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
## NEXT
## 0.8.6

* Updates minimum Flutter version to 2.10.
* Fixes avoid_redundant_argument_values lint warnings and minor typos.
* Adds `requestFullMetadata` option to `pickImage`, so images on iOS can be picked without `Photo Library Usage` permission.

## 0.8.5+3

Expand Down
1 change: 1 addition & 0 deletions packages/image_picker/image_picker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ As a result of implementing PHPicker it becomes impossible to pick HEIC images o
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.
* This permission is not required for image picking on iOS 11+ if you pass `false` for `requestFullMetadata`.
* `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.

Expand Down
2 changes: 1 addition & 1 deletion packages/image_picker/image_picker/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class _MyHomePageState extends State<MyHomePage> {
await _displayPickImageDialog(context!,
(double? maxWidth, double? maxHeight, int? quality) async {
try {
final List<XFile>? pickedFileList = await _picker.pickMultiImage(
final List<XFile> pickedFileList = await _picker.pickMultiImage(
maxWidth: maxWidth,
maxHeight: maxHeight,
imageQuality: quality,
Expand Down
70 changes: 48 additions & 22 deletions packages/image_picker/image_picker/lib/image_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -173,23 +173,32 @@ class ImagePicker {
/// The `source` argument controls where the image comes from. This can
/// be either [ImageSource.camera] or [ImageSource.gallery].
///
/// Where iOS supports HEIC images, Android 8 and below doesn't. Android 9 and above only support HEIC images if used
/// in addition to a size modification, of which the usage is explained below.
/// Where iOS supports HEIC images, Android 8 and below doesn't. Android 9 and
/// above only support HEIC images if used in addition to a size modification,
/// of which the usage is explained below.
///
/// If specified, the image will be at most `maxWidth` wide and
/// `maxHeight` tall. Otherwise the image will be returned at it's
/// original width and height.
/// The `imageQuality` argument modifies the quality of the image, ranging from 0-100
/// where 100 is the original/max quality. If `imageQuality` is null, the image with
/// the original quality will be returned. Compression is only supported for certain
/// image types such as JPEG and on Android PNG and WebP, too. If compression is not supported for the image that is picked,
/// a warning message will be logged.
///
/// Use `preferredCameraDevice` to specify the camera to use when the `source` is [ImageSource.camera].
/// The `preferredCameraDevice` is ignored when `source` is [ImageSource.gallery]. It is also ignored if the chosen camera is not supported on the device.
/// Defaults to [CameraDevice.rear]. Note that Android has no documented parameter for an intent to specify if
/// the front or rear camera should be opened, this function is not guaranteed
/// to work on an Android device.
/// image types such as JPEG and on Android PNG and WebP, too. If compression is not
/// supported for the image that is picked, a warning message will be logged.
///
/// Use `preferredCameraDevice` to specify the camera to use when the `source` is
/// [ImageSource.camera].
/// The `preferredCameraDevice` is ignored when `source` is [ImageSource.gallery].
/// It is also ignored if the chosen camera is not supported on the device.
/// Defaults to [CameraDevice.rear]. Note that Android has no documented parameter
/// for an intent to specify if the front or rear camera should be opened, this
/// function is not guaranteed to work on an Android device.
///
/// Use `requestFullMetadata` (defaults to `true`) to control how much additional
/// information the plugin tries to get.
/// If `requestFullMetadata` is set to `true`, the plugin tries to get the full
/// image metadata which may require extra permission requests on some platforms,
/// such as `Photo Library Usage` permission on iOS.
///
/// In Android, the MainActivity can be destroyed for various reasons. If that happens, the result will be lost
/// in this call. You can then call [retrieveLostData] when your app relaunches to retrieve the lost data.
Expand All @@ -206,6 +215,7 @@ class ImagePicker {
double? maxHeight,
int? imageQuality,
CameraDevice preferredCameraDevice = CameraDevice.rear,
bool requestFullMetadata = true,
}) {
if (imageQuality != null && (imageQuality < 0 || imageQuality > 100)) {
throw ArgumentError.value(
Expand All @@ -218,12 +228,15 @@ class ImagePicker {
throw ArgumentError.value(maxHeight, 'maxHeight', 'cannot be negative');
}

return platform.getImage(
return platform.getImageFromSource(
source: source,
maxWidth: maxWidth,
maxHeight: maxHeight,
imageQuality: imageQuality,
preferredCameraDevice: preferredCameraDevice,
options: ImagePickerOptions(
maxWidth: maxWidth,
maxHeight: maxHeight,
imageQuality: imageQuality,
preferredCameraDevice: preferredCameraDevice,
requestFullMetadata: requestFullMetadata,
),
);
}

Expand All @@ -239,22 +252,30 @@ class ImagePicker {
/// If specified, the images will be at most `maxWidth` wide and
/// `maxHeight` tall. Otherwise the images will be returned at it's
/// original width and height.
///
/// The `imageQuality` argument modifies the quality of the images, ranging from 0-100
/// where 100 is the original/max quality. If `imageQuality` is null, the images with
/// the original quality will be returned. Compression is only supported for certain
/// image types such as JPEG and on Android PNG and WebP, too. If compression is not supported for the image that is picked,
/// a warning message will be logged.
/// image types such as JPEG and on Android PNG and WebP, too. If compression is not
/// supported for the image that is picked, a warning message will be logged.
///
/// Use `requestFullMetadata` (defaults to `true`) to control how much additional
/// information the plugin tries to get.
/// If `requestFullMetadata` is set to `true`, the plugin tries to get the full
/// image metadata which may require extra permission requests on some platforms,
/// such as `Photo Library Usage` permission on iOS.
///
/// The method could throw [PlatformException] if the app does not have permission to access
/// the camera or photos gallery, no camera is available, plugin is already in use,
/// temporary file could not be created (iOS only), plugin activity could not
/// be allocated (Android only) or due to an unknown error.
///
/// See also [pickImage] to allow users to only pick a single image.
Future<List<XFile>?> pickMultiImage({
Future<List<XFile>> pickMultiImage({
double? maxWidth,
double? maxHeight,
int? imageQuality,
bool requestFullMetadata = true,
}) {
if (imageQuality != null && (imageQuality < 0 || imageQuality > 100)) {
throw ArgumentError.value(
Expand All @@ -267,10 +288,15 @@ class ImagePicker {
throw ArgumentError.value(maxHeight, 'maxHeight', 'cannot be negative');
}

return platform.getMultiImage(
maxWidth: maxWidth,
maxHeight: maxHeight,
imageQuality: imageQuality,
return platform.getMultiImageWithOptions(
options: MultiImagePickerOptions(
imageOptions: ImageOptions(
maxWidth: maxWidth,
maxHeight: maxHeight,
imageQuality: imageQuality,
requestFullMetadata: requestFullMetadata,
),
),
);
}

Expand Down
6 changes: 3 additions & 3 deletions packages/image_picker/image_picker/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Flutter plugin for selecting images from the Android and iOS image
library, and taking new pictures with the camera.
repository: https://github.com/flutter/plugins/tree/main/packages/image_picker/image_picker
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+image_picker%22
version: 0.8.5+3
version: 0.8.6

environment:
sdk: ">=2.14.0 <3.0.0"
Expand All @@ -24,8 +24,8 @@ dependencies:
sdk: flutter
image_picker_android: ^0.8.4+11
image_picker_for_web: ^2.1.0
image_picker_ios: ^0.8.4+11
image_picker_platform_interface: ^2.3.0
image_picker_ios: ^0.8.6+1
image_picker_platform_interface: ^2.6.1

dev_dependencies:
build_runner: ^2.1.10
Expand Down
Loading

0 comments on commit fb5c86c

Please sign in to comment.