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

Commit 998f51f

Browse files
authored
[image_picker] add forceFullMetadata to interface (#4288)
1 parent 300100b commit 998f51f

File tree

6 files changed

+69
-19
lines changed

6 files changed

+69
-19
lines changed

packages/image_picker/image_picker_for_web/lib/image_picker_for_web.dart

+2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class ImagePickerPlugin extends ImagePickerPlatform {
5353
double? maxWidth,
5454
double? maxHeight,
5555
int? imageQuality,
56+
bool forceFullMetadata = true,
5657
CameraDevice preferredCameraDevice = CameraDevice.rear,
5758
}) {
5859
String? capture = computeCaptureAttribute(source, preferredCameraDevice);
@@ -115,6 +116,7 @@ class ImagePickerPlugin extends ImagePickerPlatform {
115116
double? maxWidth,
116117
double? maxHeight,
117118
int? imageQuality,
119+
bool forceFullMetadata = true,
118120
CameraDevice preferredCameraDevice = CameraDevice.rear,
119121
}) async {
120122
String? capture = computeCaptureAttribute(source, preferredCameraDevice);

packages/image_picker/image_picker_platform_interface/CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## 2.4.0
2+
3+
* Add `forceFullMetadata` option to `pickImage`.
4+
* To keep this non-breaking `forceFullMetadata` defaults to `true`, so the plugin tries
5+
to get the full image metadata which may require extra permission requests on certain platforms.
6+
* If `forceFullMetadata` is set to `false`, the plugin fetches the image in a way that reduces
7+
permission requests from the platform (e.g on iOS the plugin won’t ask for the `NSPhotoLibraryUsageDescription` permission).
8+
19
## 2.3.0
210

311
* Updated `LostDataResponse` to include a `files` property, in case more than one file was recovered.

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

+6
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ class MethodChannelImagePicker extends ImagePickerPlatform {
2424
double? maxWidth,
2525
double? maxHeight,
2626
int? imageQuality,
27+
bool forceFullMetadata = true,
2728
CameraDevice preferredCameraDevice = CameraDevice.rear,
2829
}) async {
2930
String? path = await _getImagePath(
3031
source: source,
3132
maxWidth: maxWidth,
3233
maxHeight: maxHeight,
3334
imageQuality: imageQuality,
35+
forceFullMetadata: forceFullMetadata,
3436
preferredCameraDevice: preferredCameraDevice,
3537
);
3638
return path != null ? PickedFile(path) : null;
@@ -85,6 +87,7 @@ class MethodChannelImagePicker extends ImagePickerPlatform {
8587
double? maxWidth,
8688
double? maxHeight,
8789
int? imageQuality,
90+
bool forceFullMetadata = true,
8891
CameraDevice preferredCameraDevice = CameraDevice.rear,
8992
}) {
9093
if (imageQuality != null && (imageQuality < 0 || imageQuality > 100)) {
@@ -107,6 +110,7 @@ class MethodChannelImagePicker extends ImagePickerPlatform {
107110
'maxWidth': maxWidth,
108111
'maxHeight': maxHeight,
109112
'imageQuality': imageQuality,
113+
'forceFullMetadata': forceFullMetadata,
110114
'cameraDevice': preferredCameraDevice.index
111115
},
112116
);
@@ -183,13 +187,15 @@ class MethodChannelImagePicker extends ImagePickerPlatform {
183187
double? maxWidth,
184188
double? maxHeight,
185189
int? imageQuality,
190+
bool forceFullMetadata = true,
186191
CameraDevice preferredCameraDevice = CameraDevice.rear,
187192
}) async {
188193
String? path = await _getImagePath(
189194
source: source,
190195
maxWidth: maxWidth,
191196
maxHeight: maxHeight,
192197
imageQuality: imageQuality,
198+
forceFullMetadata: forceFullMetadata,
193199
preferredCameraDevice: preferredCameraDevice,
194200
);
195201
return path != null ? XFile(path) : null;

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

+12
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ abstract class ImagePickerPlatform extends PlatformInterface {
5858
/// image types such as JPEG. If compression is not supported for the image that is picked,
5959
/// a warning message will be logged.
6060
///
61+
/// `forceFullMetadata` defaults to `true`, so the plugin tries to get the full image metadata which may require
62+
/// extra permission requests on certain platforms.
63+
/// If `forceFullMetadata` is set to `false`, the plugin fetches the image in a way that reduces permission requests
64+
/// from the platform (e.g. on iOS the plugin won’t ask for the `NSPhotoLibraryUsageDescription` permission).
65+
///
6166
/// Use `preferredCameraDevice` to specify the camera to use when the `source` is [ImageSource.camera].
6267
/// The `preferredCameraDevice` is ignored when `source` is [ImageSource.gallery]. It is also ignored if the chosen camera is not supported on the device.
6368
/// Defaults to [CameraDevice.rear]. Note that Android has no documented parameter for an intent to specify if
@@ -73,6 +78,7 @@ abstract class ImagePickerPlatform extends PlatformInterface {
7378
double? maxWidth,
7479
double? maxHeight,
7580
int? imageQuality,
81+
bool forceFullMetadata = true,
7682
CameraDevice preferredCameraDevice = CameraDevice.rear,
7783
}) {
7884
throw UnimplementedError('pickImage() has not been implemented.');
@@ -164,6 +170,11 @@ abstract class ImagePickerPlatform extends PlatformInterface {
164170
/// image types such as JPEG. If compression is not supported for the image that is picked,
165171
/// a warning message will be logged.
166172
///
173+
/// `forceFullMetadata` defaults to `true`, so the plugin tries to get the full image metadata which may require
174+
/// extra permission requests on certain platforms.
175+
/// If `forceFullMetadata` is set to `false`, the plugin fetches the image in a way that reduces permission requests
176+
/// from the platform (e.g. on iOS the plugin won’t ask for the `NSPhotoLibraryUsageDescription` permission).
177+
///
167178
/// Use `preferredCameraDevice` to specify the camera to use when the `source` is [ImageSource.camera].
168179
/// The `preferredCameraDevice` is ignored when `source` is [ImageSource.gallery]. It is also ignored if the chosen camera is not supported on the device.
169180
/// Defaults to [CameraDevice.rear]. Note that Android has no documented parameter for an intent to specify if
@@ -179,6 +190,7 @@ abstract class ImagePickerPlatform extends PlatformInterface {
179190
double? maxWidth,
180191
double? maxHeight,
181192
int? imageQuality,
193+
bool forceFullMetadata = true,
182194
CameraDevice preferredCameraDevice = CameraDevice.rear,
183195
}) {
184196
throw UnimplementedError('getImage() has not been implemented.');

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/master/packages/image_picker
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.3.0
7+
version: 2.4.0
88

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

packages/image_picker/image_picker_platform_interface/test/new_method_channel_image_picker_test.dart

+40-18
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,16 @@ void main() {
4040
'maxWidth': null,
4141
'maxHeight': null,
4242
'imageQuality': null,
43-
'cameraDevice': 0
43+
'cameraDevice': 0,
44+
'forceFullMetadata': true,
4445
}),
4546
isMethodCall('pickImage', arguments: <String, dynamic>{
4647
'source': 1,
4748
'maxWidth': null,
4849
'maxHeight': null,
4950
'imageQuality': null,
50-
'cameraDevice': 0
51+
'cameraDevice': 0,
52+
'forceFullMetadata': true,
5153
}),
5254
],
5355
);
@@ -93,49 +95,56 @@ void main() {
9395
'maxWidth': null,
9496
'maxHeight': null,
9597
'imageQuality': null,
96-
'cameraDevice': 0
98+
'cameraDevice': 0,
99+
'forceFullMetadata': true,
97100
}),
98101
isMethodCall('pickImage', arguments: <String, dynamic>{
99102
'source': 0,
100103
'maxWidth': 10.0,
101104
'maxHeight': null,
102105
'imageQuality': null,
103-
'cameraDevice': 0
106+
'cameraDevice': 0,
107+
'forceFullMetadata': true,
104108
}),
105109
isMethodCall('pickImage', arguments: <String, dynamic>{
106110
'source': 0,
107111
'maxWidth': null,
108112
'maxHeight': 10.0,
109113
'imageQuality': null,
110-
'cameraDevice': 0
114+
'cameraDevice': 0,
115+
'forceFullMetadata': true,
111116
}),
112117
isMethodCall('pickImage', arguments: <String, dynamic>{
113118
'source': 0,
114119
'maxWidth': 10.0,
115120
'maxHeight': 20.0,
116121
'imageQuality': null,
117-
'cameraDevice': 0
122+
'cameraDevice': 0,
123+
'forceFullMetadata': true,
118124
}),
119125
isMethodCall('pickImage', arguments: <String, dynamic>{
120126
'source': 0,
121127
'maxWidth': 10.0,
122128
'maxHeight': null,
123129
'imageQuality': 70,
124-
'cameraDevice': 0
130+
'cameraDevice': 0,
131+
'forceFullMetadata': true,
125132
}),
126133
isMethodCall('pickImage', arguments: <String, dynamic>{
127134
'source': 0,
128135
'maxWidth': null,
129136
'maxHeight': 10.0,
130137
'imageQuality': 70,
131-
'cameraDevice': 0
138+
'cameraDevice': 0,
139+
'forceFullMetadata': true,
132140
}),
133141
isMethodCall('pickImage', arguments: <String, dynamic>{
134142
'source': 0,
135143
'maxWidth': 10.0,
136144
'maxHeight': 20.0,
137145
'imageQuality': 70,
138-
'cameraDevice': 0
146+
'cameraDevice': 0,
147+
'forceFullMetadata': true,
139148
}),
140149
],
141150
);
@@ -196,6 +205,7 @@ void main() {
196205
'maxHeight': null,
197206
'imageQuality': null,
198207
'cameraDevice': 0,
208+
'forceFullMetadata': true,
199209
}),
200210
],
201211
);
@@ -215,6 +225,7 @@ void main() {
215225
'maxHeight': null,
216226
'imageQuality': null,
217227
'cameraDevice': 1,
228+
'forceFullMetadata': true,
218229
}),
219230
],
220231
);
@@ -509,14 +520,16 @@ void main() {
509520
'maxWidth': null,
510521
'maxHeight': null,
511522
'imageQuality': null,
512-
'cameraDevice': 0
523+
'cameraDevice': 0,
524+
'forceFullMetadata': true,
513525
}),
514526
isMethodCall('pickImage', arguments: <String, dynamic>{
515527
'source': 1,
516528
'maxWidth': null,
517529
'maxHeight': null,
518530
'imageQuality': null,
519-
'cameraDevice': 0
531+
'cameraDevice': 0,
532+
'forceFullMetadata': true,
520533
}),
521534
],
522535
);
@@ -562,49 +575,56 @@ void main() {
562575
'maxWidth': null,
563576
'maxHeight': null,
564577
'imageQuality': null,
565-
'cameraDevice': 0
578+
'cameraDevice': 0,
579+
'forceFullMetadata': true,
566580
}),
567581
isMethodCall('pickImage', arguments: <String, dynamic>{
568582
'source': 0,
569583
'maxWidth': 10.0,
570584
'maxHeight': null,
571585
'imageQuality': null,
572-
'cameraDevice': 0
586+
'cameraDevice': 0,
587+
'forceFullMetadata': true,
573588
}),
574589
isMethodCall('pickImage', arguments: <String, dynamic>{
575590
'source': 0,
576591
'maxWidth': null,
577592
'maxHeight': 10.0,
578593
'imageQuality': null,
579-
'cameraDevice': 0
594+
'cameraDevice': 0,
595+
'forceFullMetadata': true,
580596
}),
581597
isMethodCall('pickImage', arguments: <String, dynamic>{
582598
'source': 0,
583599
'maxWidth': 10.0,
584600
'maxHeight': 20.0,
585601
'imageQuality': null,
586-
'cameraDevice': 0
602+
'cameraDevice': 0,
603+
'forceFullMetadata': true,
587604
}),
588605
isMethodCall('pickImage', arguments: <String, dynamic>{
589606
'source': 0,
590607
'maxWidth': 10.0,
591608
'maxHeight': null,
592609
'imageQuality': 70,
593-
'cameraDevice': 0
610+
'cameraDevice': 0,
611+
'forceFullMetadata': true,
594612
}),
595613
isMethodCall('pickImage', arguments: <String, dynamic>{
596614
'source': 0,
597615
'maxWidth': null,
598616
'maxHeight': 10.0,
599617
'imageQuality': 70,
600-
'cameraDevice': 0
618+
'cameraDevice': 0,
619+
'forceFullMetadata': true,
601620
}),
602621
isMethodCall('pickImage', arguments: <String, dynamic>{
603622
'source': 0,
604623
'maxWidth': 10.0,
605624
'maxHeight': 20.0,
606625
'imageQuality': 70,
607-
'cameraDevice': 0
626+
'cameraDevice': 0,
627+
'forceFullMetadata': true,
608628
}),
609629
],
610630
);
@@ -664,6 +684,7 @@ void main() {
664684
'maxHeight': null,
665685
'imageQuality': null,
666686
'cameraDevice': 0,
687+
'forceFullMetadata': true,
667688
}),
668689
],
669690
);
@@ -683,6 +704,7 @@ void main() {
683704
'maxHeight': null,
684705
'imageQuality': null,
685706
'cameraDevice': 1,
707+
'forceFullMetadata': true,
686708
}),
687709
],
688710
);

0 commit comments

Comments
 (0)