Skip to content

Commit 278bc66

Browse files
[image_picker] add requestFullMetadata for iOS (optional permissions) - platform interface changes for multi image picking (#5914)
Platform interface changes for #5915 - adding possibility to disable full metadata when picking multiple images
1 parent 300f970 commit 278bc66

File tree

7 files changed

+331
-1
lines changed

7 files changed

+331
-1
lines changed

packages/image_picker/image_picker_platform_interface/CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 2.6.0
2+
3+
* Deprecates `getMultiImage` in favor of a new method `getMultiImageWithOptions`.
4+
* Adds `requestFullMetadata` option that allows disabling extra permission requests
5+
on certain platforms.
6+
* Moves optional image picking parameters to `MultiImagePickerOptions` class.
7+
18
## 2.5.0
29

310
* Deprecates `getImage` in favor of a new method `getImageFromSource`.

packages/image_picker/image_picker_platform_interface/lib/src/method_channel/method_channel_image_picker.dart

+20
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'package:flutter/foundation.dart';
88
import 'package:flutter/services.dart';
99

1010
import 'package:image_picker_platform_interface/image_picker_platform_interface.dart';
11+
import 'package:image_picker_platform_interface/src/types/multi_image_picker_options.dart';
1112

1213
const MethodChannel _channel = MethodChannel('plugins.flutter.io/image_picker');
1314

@@ -57,6 +58,7 @@ class MethodChannelImagePicker extends ImagePickerPlatform {
5758
double? maxWidth,
5859
double? maxHeight,
5960
int? imageQuality,
61+
bool requestFullMetadata = true,
6062
}) {
6163
if (imageQuality != null && (imageQuality < 0 || imageQuality > 100)) {
6264
throw ArgumentError.value(
@@ -77,6 +79,7 @@ class MethodChannelImagePicker extends ImagePickerPlatform {
7779
'maxWidth': maxWidth,
7880
'maxHeight': maxHeight,
7981
'imageQuality': imageQuality,
82+
'requestFullMetadata': requestFullMetadata,
8083
},
8184
);
8285
}
@@ -233,6 +236,23 @@ class MethodChannelImagePicker extends ImagePickerPlatform {
233236
return paths.map((dynamic path) => XFile(path as String)).toList();
234237
}
235238

239+
@override
240+
Future<List<XFile>> getMultiImageWithOptions({
241+
MultiImagePickerOptions options = const MultiImagePickerOptions(),
242+
}) async {
243+
final List<dynamic>? paths = await _getMultiImagePath(
244+
maxWidth: options.imageOptions.maxWidth,
245+
maxHeight: options.imageOptions.maxHeight,
246+
imageQuality: options.imageOptions.imageQuality,
247+
requestFullMetadata: options.imageOptions.requestFullMetadata,
248+
);
249+
if (paths == null) {
250+
return <XFile>[];
251+
}
252+
253+
return paths.map((dynamic path) => XFile(path as String)).toList();
254+
}
255+
236256
@override
237257
Future<XFile?> getVideo({
238258
required ImageSource source,

packages/image_picker/image_picker_platform_interface/lib/src/platform_interface/image_picker_platform.dart

+22
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'dart:async';
66

77
import 'package:cross_file/cross_file.dart';
88
import 'package:image_picker_platform_interface/src/method_channel/method_channel_image_picker.dart';
9+
import 'package:image_picker_platform_interface/src/types/multi_image_picker_options.dart';
910
import 'package:image_picker_platform_interface/src/types/types.dart';
1011
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
1112

@@ -186,6 +187,8 @@ abstract class ImagePickerPlatform extends PlatformInterface {
186187
throw UnimplementedError('getImage() has not been implemented.');
187188
}
188189

190+
/// This method is deprecated in favor of [getMultiImageWithOptions] and will be removed in a future update.
191+
///
189192
/// Returns a [List<XFile>] with the images that were picked.
190193
///
191194
/// The images come from the [ImageSource.gallery].
@@ -283,4 +286,23 @@ abstract class ImagePickerPlatform extends PlatformInterface {
283286
preferredCameraDevice: options.preferredCameraDevice,
284287
);
285288
}
289+
290+
/// Returns a [List<XFile>] with the images that were picked.
291+
///
292+
/// The images come from the [ImageSource.gallery].
293+
///
294+
/// The `options` argument controls additional settings that can be used when
295+
/// picking an image. See [MultiImagePickerOptions] for more details.
296+
///
297+
/// If no images were picked, returns an empty list.
298+
Future<List<XFile>> getMultiImageWithOptions({
299+
MultiImagePickerOptions options = const MultiImagePickerOptions(),
300+
}) async {
301+
final List<XFile>? pickedImages = await getMultiImage(
302+
maxWidth: options.imageOptions.maxWidth,
303+
maxHeight: options.imageOptions.maxHeight,
304+
imageQuality: options.imageOptions.imageQuality,
305+
);
306+
return pickedImages ?? <XFile>[];
307+
}
286308
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
/// Specifies image-specific options for picking.
6+
class ImageOptions {
7+
/// Creates an instance with the given [maxHeight], [maxWidth], [imageQuality]
8+
/// and [requestFullMetadata].
9+
const ImageOptions({
10+
this.maxHeight,
11+
this.maxWidth,
12+
this.imageQuality,
13+
this.requestFullMetadata = true,
14+
});
15+
16+
/// The maximum width of the image, in pixels.
17+
///
18+
/// If null, the image will only be resized if [maxHeight] is specified.
19+
final double? maxWidth;
20+
21+
/// The maximum height of the image, in pixels.
22+
///
23+
/// If null, the image will only be resized if [maxWidth] is specified.
24+
final double? maxHeight;
25+
26+
/// Modifies the quality of the image, ranging from 0-100 where 100 is the
27+
/// original/max quality.
28+
///
29+
/// Compression is only supported for certain image types such as JPEG. If
30+
/// compression is not supported for the image that is picked, a warning
31+
/// message will be logged.
32+
///
33+
/// If null, the image will be returned with the original quality.
34+
final int? imageQuality;
35+
36+
/// If true, requests full image metadata, which may require extra permissions
37+
/// on some platforms, (e.g., NSPhotoLibraryUsageDescription on iOS).
38+
//
39+
// Defaults to true.
40+
final bool requestFullMetadata;
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:image_picker_platform_interface/src/types/image_options.dart';
6+
7+
/// Specifies options for picking multiple images from the device's gallery.
8+
class MultiImagePickerOptions {
9+
/// Creates an instance with the given [imageOptions].
10+
const MultiImagePickerOptions({
11+
this.imageOptions = const ImageOptions(),
12+
});
13+
14+
/// The image-specific options for picking.
15+
final ImageOptions imageOptions;
16+
}

packages/image_picker/image_picker_platform_interface/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ repository: https://github.com/flutter/plugins/tree/main/packages/image_picker/i
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+image_picker%22
55
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
66
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
7-
version: 2.5.0
7+
version: 2.6.0
88

99
environment:
1010
sdk: ">=2.12.0 <3.0.0"

0 commit comments

Comments
 (0)