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

Commit ed4bcea

Browse files
committed
[image_picker] fix tests & run auto-formatter
1 parent f11baad commit ed4bcea

File tree

7 files changed

+68
-29
lines changed

7 files changed

+68
-29
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ class _MyHomePageState extends State<MyHomePage> {
8888
source: source, maxDuration: const Duration(seconds: 10));
8989
await _playVideo(file);
9090
} else if (isMultiImage) {
91-
await _displayPickImageDialog(context!,
92-
(double? maxWidth, double? maxHeight, int? quality) async {
91+
await _displayPickImageDialog(context!, (double? maxWidth,
92+
double? maxHeight, int? quality, bool forceFullMetadata) async {
9393
try {
9494
final pickedFileList = await _picker.pickMultiImage(
9595
maxWidth: maxWidth,
@@ -106,8 +106,8 @@ class _MyHomePageState extends State<MyHomePage> {
106106
}
107107
});
108108
} else {
109-
await _displayPickImageDialog(context!,
110-
(double? maxWidth, double? maxHeight, int? quality, bool forceFullMetadata) async {
109+
await _displayPickImageDialog(context!, (double? maxWidth,
110+
double? maxHeight, int? quality, bool forceFullMetadata) async {
111111
try {
112112
final pickedFile = await _picker.pickImage(
113113
source: source,
@@ -367,13 +367,15 @@ class _MyHomePageState extends State<MyHomePage> {
367367
children: <Widget>[
368368
TextField(
369369
controller: maxWidthController,
370-
keyboardType: TextInputType.numberWithOptions(decimal: true),
370+
keyboardType:
371+
TextInputType.numberWithOptions(decimal: true),
371372
decoration:
372373
InputDecoration(hintText: "Enter maxWidth if desired"),
373374
),
374375
TextField(
375376
controller: maxHeightController,
376-
keyboardType: TextInputType.numberWithOptions(decimal: true),
377+
keyboardType:
378+
TextInputType.numberWithOptions(decimal: true),
377379
decoration:
378380
InputDecoration(hintText: "Enter maxHeight if desired"),
379381
),

packages/image_picker/image_picker/ios/Classes/FLTImagePickerPlugin.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,12 @@ - (void)pickImageWithUIImagePicker {
119119
[self checkCameraAuthorization];
120120
break;
121121
case SOURCE_GALLERY:
122-
if (usePhaAsset) {
123-
[self checkPhotoAuthorization];
124-
break;
125-
}
126-
[self showPhotoLibrary:UIImagePickerClassType];
122+
if (usePhaAsset) {
123+
[self checkPhotoAuthorization];
127124
break;
125+
}
126+
[self showPhotoLibrary:UIImagePickerClassType];
127+
break;
128128
default:
129129
self.result([FlutterError errorWithCode:@"invalid_source"
130130
message:@"Invalid image source."

packages/image_picker/image_picker/lib/image_picker.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@ class ImagePicker {
192192
/// image types such as JPEG and on Android PNG and WebP, too. If compression is not supported for the image that is picked,
193193
/// a warning message will be logged.
194194
///
195+
/// `forceFullMetadata` defaults to `true`, so the plugin tries to get the full image metadata which may require
196+
/// extra permission requests on certain platforms.
197+
/// If `forceFullMetadata` is set to `false`, the plugin fetches the image in a way that reduces permission requests
198+
/// from the platform (e.g on iOS the plugin won’t ask for the `NSPhotoLibraryUsageDescription` permission).
199+
///
195200
/// Use `preferredCameraDevice` to specify the camera to use when the `source` is [ImageSource.camera].
196201
/// The `preferredCameraDevice` is ignored when `source` is [ImageSource.gallery]. It is also ignored if the chosen camera is not supported on the device.
197202
/// Defaults to [CameraDevice.rear]. Note that Android has no documented parameter for an intent to specify if
@@ -212,13 +217,15 @@ class ImagePicker {
212217
double? maxWidth,
213218
double? maxHeight,
214219
int? imageQuality,
220+
bool forceFullMetadata = true,
215221
CameraDevice preferredCameraDevice = CameraDevice.rear,
216222
}) {
217223
return platform.getImage(
218224
source: source,
219225
maxWidth: maxWidth,
220226
maxHeight: maxHeight,
221227
imageQuality: imageQuality,
228+
forceFullMetadata: forceFullMetadata,
222229
preferredCameraDevice: preferredCameraDevice,
223230
);
224231
}

packages/image_picker/image_picker/test/image_picker_deprecated_test.dart

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,16 @@ void main() {
5757
'maxWidth': null,
5858
'maxHeight': null,
5959
'imageQuality': null,
60-
'cameraDevice': 0
60+
'cameraDevice': 0,
61+
'forceFullMetadata': true,
6162
}),
6263
isMethodCall('pickImage', arguments: <String, dynamic>{
6364
'source': 1,
6465
'maxWidth': null,
6566
'maxHeight': null,
6667
'imageQuality': null,
67-
'cameraDevice': 0
68+
'cameraDevice': 0,
69+
'forceFullMetadata': true,
6870
}),
6971
],
7072
);
@@ -103,49 +105,56 @@ void main() {
103105
'maxWidth': null,
104106
'maxHeight': null,
105107
'imageQuality': null,
106-
'cameraDevice': 0
108+
'cameraDevice': 0,
109+
'forceFullMetadata': true,
107110
}),
108111
isMethodCall('pickImage', arguments: <String, dynamic>{
109112
'source': 0,
110113
'maxWidth': 10.0,
111114
'maxHeight': null,
112115
'imageQuality': null,
113-
'cameraDevice': 0
116+
'cameraDevice': 0,
117+
'forceFullMetadata': true,
114118
}),
115119
isMethodCall('pickImage', arguments: <String, dynamic>{
116120
'source': 0,
117121
'maxWidth': null,
118122
'maxHeight': 10.0,
119123
'imageQuality': null,
120-
'cameraDevice': 0
124+
'cameraDevice': 0,
125+
'forceFullMetadata': true,
121126
}),
122127
isMethodCall('pickImage', arguments: <String, dynamic>{
123128
'source': 0,
124129
'maxWidth': 10.0,
125130
'maxHeight': 20.0,
126131
'imageQuality': null,
127-
'cameraDevice': 0
132+
'cameraDevice': 0,
133+
'forceFullMetadata': true,
128134
}),
129135
isMethodCall('pickImage', arguments: <String, dynamic>{
130136
'source': 0,
131137
'maxWidth': 10.0,
132138
'maxHeight': null,
133139
'imageQuality': 70,
134-
'cameraDevice': 0
140+
'cameraDevice': 0,
141+
'forceFullMetadata': true,
135142
}),
136143
isMethodCall('pickImage', arguments: <String, dynamic>{
137144
'source': 0,
138145
'maxWidth': null,
139146
'maxHeight': 10.0,
140147
'imageQuality': 70,
141-
'cameraDevice': 0
148+
'cameraDevice': 0,
149+
'forceFullMetadata': true,
142150
}),
143151
isMethodCall('pickImage', arguments: <String, dynamic>{
144152
'source': 0,
145153
'maxWidth': 10.0,
146154
'maxHeight': 20.0,
147155
'imageQuality': 70,
148-
'cameraDevice': 0
156+
'cameraDevice': 0,
157+
'forceFullMetadata': true,
149158
}),
150159
],
151160
);
@@ -182,6 +191,7 @@ void main() {
182191
'maxHeight': null,
183192
'imageQuality': null,
184193
'cameraDevice': 0,
194+
'forceFullMetadata': true,
185195
}),
186196
],
187197
);
@@ -201,6 +211,7 @@ void main() {
201211
'maxHeight': null,
202212
'imageQuality': null,
203213
'cameraDevice': 1,
214+
'forceFullMetadata': true,
204215
}),
205216
],
206217
);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,15 @@ class MethodChannelImagePicker extends ImagePickerPlatform {
187187
double? maxWidth,
188188
double? maxHeight,
189189
int? imageQuality,
190+
bool forceFullMetadata = true,
190191
CameraDevice preferredCameraDevice = CameraDevice.rear,
191192
}) async {
192193
String? path = await _getImagePath(
193194
source: source,
194195
maxWidth: maxWidth,
195196
maxHeight: maxHeight,
196197
imageQuality: imageQuality,
198+
forceFullMetadata: forceFullMetadata,
197199
preferredCameraDevice: preferredCameraDevice,
198200
);
199201
return path != null ? XFile(path) : null;

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ abstract class ImagePickerPlatform extends PlatformInterface {
169169
/// image types such as JPEG. If compression is not supported for the image that is picked,
170170
/// a warning message will be logged.
171171
///
172+
/// `forceFullMetadata` defaults to `true`, so the plugin tries to get the full image metadata which may require
173+
/// extra permission requests on certain platforms.
174+
/// If `forceFullMetadata` is set to `false`, the plugin fetches the image in a way that reduces permission requests
175+
/// from the platform (e.g on iOS the plugin won’t ask for the `NSPhotoLibraryUsageDescription` permission).
176+
///
172177
/// Use `preferredCameraDevice` to specify the camera to use when the `source` is [ImageSource.camera].
173178
/// The `preferredCameraDevice` is ignored when `source` is [ImageSource.gallery]. It is also ignored if the chosen camera is not supported on the device.
174179
/// Defaults to [CameraDevice.rear]. Note that Android has no documented parameter for an intent to specify if
@@ -184,6 +189,7 @@ abstract class ImagePickerPlatform extends PlatformInterface {
184189
double? maxWidth,
185190
double? maxHeight,
186191
int? imageQuality,
192+
bool forceFullMetadata = true,
187193
CameraDevice preferredCameraDevice = CameraDevice.rear,
188194
}) {
189195
throw UnimplementedError('getImage() has not been implemented.');

packages/image_picker/image_picker_platform_interface/test/new_method_channel_image_picker_test.dart

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -520,14 +520,16 @@ void main() {
520520
'maxWidth': null,
521521
'maxHeight': null,
522522
'imageQuality': null,
523-
'cameraDevice': 0
523+
'cameraDevice': 0,
524+
'forceFullMetadata': true,
524525
}),
525526
isMethodCall('pickImage', arguments: <String, dynamic>{
526527
'source': 1,
527528
'maxWidth': null,
528529
'maxHeight': null,
529530
'imageQuality': null,
530-
'cameraDevice': 0
531+
'cameraDevice': 0,
532+
'forceFullMetadata': true,
531533
}),
532534
],
533535
);
@@ -573,49 +575,56 @@ void main() {
573575
'maxWidth': null,
574576
'maxHeight': null,
575577
'imageQuality': null,
576-
'cameraDevice': 0
578+
'cameraDevice': 0,
579+
'forceFullMetadata': true,
577580
}),
578581
isMethodCall('pickImage', arguments: <String, dynamic>{
579582
'source': 0,
580583
'maxWidth': 10.0,
581584
'maxHeight': null,
582585
'imageQuality': null,
583-
'cameraDevice': 0
586+
'cameraDevice': 0,
587+
'forceFullMetadata': true,
584588
}),
585589
isMethodCall('pickImage', arguments: <String, dynamic>{
586590
'source': 0,
587591
'maxWidth': null,
588592
'maxHeight': 10.0,
589593
'imageQuality': null,
590-
'cameraDevice': 0
594+
'cameraDevice': 0,
595+
'forceFullMetadata': true,
591596
}),
592597
isMethodCall('pickImage', arguments: <String, dynamic>{
593598
'source': 0,
594599
'maxWidth': 10.0,
595600
'maxHeight': 20.0,
596601
'imageQuality': null,
597-
'cameraDevice': 0
602+
'cameraDevice': 0,
603+
'forceFullMetadata': true,
598604
}),
599605
isMethodCall('pickImage', arguments: <String, dynamic>{
600606
'source': 0,
601607
'maxWidth': 10.0,
602608
'maxHeight': null,
603609
'imageQuality': 70,
604-
'cameraDevice': 0
610+
'cameraDevice': 0,
611+
'forceFullMetadata': true,
605612
}),
606613
isMethodCall('pickImage', arguments: <String, dynamic>{
607614
'source': 0,
608615
'maxWidth': null,
609616
'maxHeight': 10.0,
610617
'imageQuality': 70,
611-
'cameraDevice': 0
618+
'cameraDevice': 0,
619+
'forceFullMetadata': true,
612620
}),
613621
isMethodCall('pickImage', arguments: <String, dynamic>{
614622
'source': 0,
615623
'maxWidth': 10.0,
616624
'maxHeight': 20.0,
617625
'imageQuality': 70,
618-
'cameraDevice': 0
626+
'cameraDevice': 0,
627+
'forceFullMetadata': true,
619628
}),
620629
],
621630
);
@@ -675,6 +684,7 @@ void main() {
675684
'maxHeight': null,
676685
'imageQuality': null,
677686
'cameraDevice': 0,
687+
'forceFullMetadata': true,
678688
}),
679689
],
680690
);
@@ -694,6 +704,7 @@ void main() {
694704
'maxHeight': null,
695705
'imageQuality': null,
696706
'cameraDevice': 1,
707+
'forceFullMetadata': true,
697708
}),
698709
],
699710
);

0 commit comments

Comments
 (0)