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

Commit fb5c86c

Browse files
[image_picker] add requestFullMetadata for iOS (optional permissions) (#5915)
1 parent 3a928b8 commit fb5c86c

File tree

7 files changed

+386
-69
lines changed

7 files changed

+386
-69
lines changed

packages/image_picker/image_picker/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
## NEXT
1+
## 0.8.6
22

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

67
## 0.8.5+3
78

packages/image_picker/image_picker/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ As a result of implementing PHPicker it becomes impossible to pick HEIC images o
2323
Add the following keys to your _Info.plist_ file, located in `<project root>/ios/Runner/Info.plist`:
2424

2525
* `NSPhotoLibraryUsageDescription` - describe why your app needs permission for the photo library. This is called _Privacy - Photo Library Usage Description_ in the visual editor.
26+
* This permission is not required for image picking on iOS 11+ if you pass `false` for `requestFullMetadata`.
2627
* `NSCameraUsageDescription` - describe why your app needs access to the camera. This is called _Privacy - Camera Usage Description_ in the visual editor.
2728
* `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.
2829

packages/image_picker/image_picker/example/lib/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class _MyHomePageState extends State<MyHomePage> {
9393
await _displayPickImageDialog(context!,
9494
(double? maxWidth, double? maxHeight, int? quality) async {
9595
try {
96-
final List<XFile>? pickedFileList = await _picker.pickMultiImage(
96+
final List<XFile> pickedFileList = await _picker.pickMultiImage(
9797
maxWidth: maxWidth,
9898
maxHeight: maxHeight,
9999
imageQuality: quality,

packages/image_picker/image_picker/lib/image_picker.dart

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -173,23 +173,32 @@ class ImagePicker {
173173
/// The `source` argument controls where the image comes from. This can
174174
/// be either [ImageSource.camera] or [ImageSource.gallery].
175175
///
176-
/// Where iOS supports HEIC images, Android 8 and below doesn't. Android 9 and above only support HEIC images if used
177-
/// in addition to a size modification, of which the usage is explained below.
176+
/// Where iOS supports HEIC images, Android 8 and below doesn't. Android 9 and
177+
/// above only support HEIC images if used in addition to a size modification,
178+
/// of which the usage is explained below.
178179
///
179180
/// If specified, the image will be at most `maxWidth` wide and
180181
/// `maxHeight` tall. Otherwise the image will be returned at it's
181182
/// original width and height.
182183
/// The `imageQuality` argument modifies the quality of the image, ranging from 0-100
183184
/// where 100 is the original/max quality. If `imageQuality` is null, the image with
184185
/// the original quality will be returned. Compression is only supported for certain
185-
/// image types such as JPEG and on Android PNG and WebP, too. If compression is not supported for the image that is picked,
186-
/// a warning message will be logged.
187-
///
188-
/// Use `preferredCameraDevice` to specify the camera to use when the `source` is [ImageSource.camera].
189-
/// The `preferredCameraDevice` is ignored when `source` is [ImageSource.gallery]. It is also ignored if the chosen camera is not supported on the device.
190-
/// Defaults to [CameraDevice.rear]. Note that Android has no documented parameter for an intent to specify if
191-
/// the front or rear camera should be opened, this function is not guaranteed
192-
/// to work on an Android device.
186+
/// image types such as JPEG and on Android PNG and WebP, too. If compression is not
187+
/// supported for the image that is picked, a warning message will be logged.
188+
///
189+
/// Use `preferredCameraDevice` to specify the camera to use when the `source` is
190+
/// [ImageSource.camera].
191+
/// The `preferredCameraDevice` is ignored when `source` is [ImageSource.gallery].
192+
/// It is also ignored if the chosen camera is not supported on the device.
193+
/// Defaults to [CameraDevice.rear]. Note that Android has no documented parameter
194+
/// for an intent to specify if the front or rear camera should be opened, this
195+
/// function is not guaranteed to work on an Android device.
196+
///
197+
/// Use `requestFullMetadata` (defaults to `true`) to control how much additional
198+
/// information the plugin tries to get.
199+
/// If `requestFullMetadata` is set to `true`, the plugin tries to get the full
200+
/// image metadata which may require extra permission requests on some platforms,
201+
/// such as `Photo Library Usage` permission on iOS.
193202
///
194203
/// In Android, the MainActivity can be destroyed for various reasons. If that happens, the result will be lost
195204
/// in this call. You can then call [retrieveLostData] when your app relaunches to retrieve the lost data.
@@ -206,6 +215,7 @@ class ImagePicker {
206215
double? maxHeight,
207216
int? imageQuality,
208217
CameraDevice preferredCameraDevice = CameraDevice.rear,
218+
bool requestFullMetadata = true,
209219
}) {
210220
if (imageQuality != null && (imageQuality < 0 || imageQuality > 100)) {
211221
throw ArgumentError.value(
@@ -218,12 +228,15 @@ class ImagePicker {
218228
throw ArgumentError.value(maxHeight, 'maxHeight', 'cannot be negative');
219229
}
220230

221-
return platform.getImage(
231+
return platform.getImageFromSource(
222232
source: source,
223-
maxWidth: maxWidth,
224-
maxHeight: maxHeight,
225-
imageQuality: imageQuality,
226-
preferredCameraDevice: preferredCameraDevice,
233+
options: ImagePickerOptions(
234+
maxWidth: maxWidth,
235+
maxHeight: maxHeight,
236+
imageQuality: imageQuality,
237+
preferredCameraDevice: preferredCameraDevice,
238+
requestFullMetadata: requestFullMetadata,
239+
),
227240
);
228241
}
229242

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

270-
return platform.getMultiImage(
271-
maxWidth: maxWidth,
272-
maxHeight: maxHeight,
273-
imageQuality: imageQuality,
291+
return platform.getMultiImageWithOptions(
292+
options: MultiImagePickerOptions(
293+
imageOptions: ImageOptions(
294+
maxWidth: maxWidth,
295+
maxHeight: maxHeight,
296+
imageQuality: imageQuality,
297+
requestFullMetadata: requestFullMetadata,
298+
),
299+
),
274300
);
275301
}
276302

packages/image_picker/image_picker/pubspec.yaml

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

88
environment:
99
sdk: ">=2.14.0 <3.0.0"
@@ -24,8 +24,8 @@ dependencies:
2424
sdk: flutter
2525
image_picker_android: ^0.8.4+11
2626
image_picker_for_web: ^2.1.0
27-
image_picker_ios: ^0.8.4+11
28-
image_picker_platform_interface: ^2.3.0
27+
image_picker_ios: ^0.8.6+1
28+
image_picker_platform_interface: ^2.6.1
2929

3030
dev_dependencies:
3131
build_runner: ^2.1.10

0 commit comments

Comments
 (0)