From cf182094b44af6d9444bf17474a490469e57af8f Mon Sep 17 00:00:00 2001 From: "daniel.roek" Date: Wed, 10 Mar 2021 12:23:31 +0100 Subject: [PATCH 1/9] Added pickMultiImage to image_picker_platform_interface --- .../CHANGELOG.md | 4 ++ .../method_channel_image_picker.dart | 46 +++++++++++++++++++ .../image_picker_platform.dart | 30 +++++++++++- .../pubspec.yaml | 2 +- 4 files changed, 79 insertions(+), 3 deletions(-) diff --git a/packages/image_picker/image_picker_platform_interface/CHANGELOG.md b/packages/image_picker/image_picker_platform_interface/CHANGELOG.md index 598f83b4b09b..266654eff6fc 100644 --- a/packages/image_picker/image_picker_platform_interface/CHANGELOG.md +++ b/packages/image_picker/image_picker_platform_interface/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.1.0 + +* Added pickMultiImage call + ## 2.0.1 * Update platform_plugin_interface version requirement. diff --git a/packages/image_picker/image_picker_platform_interface/lib/src/method_channel/method_channel_image_picker.dart b/packages/image_picker/image_picker_platform_interface/lib/src/method_channel/method_channel_image_picker.dart index 8535f9dfb20e..31847a188d84 100644 --- a/packages/image_picker/image_picker_platform_interface/lib/src/method_channel/method_channel_image_picker.dart +++ b/packages/image_picker/image_picker_platform_interface/lib/src/method_channel/method_channel_image_picker.dart @@ -36,6 +36,52 @@ class MethodChannelImagePicker extends ImagePickerPlatform { return path != null ? PickedFile(path) : null; } + @override + Future?> pickMultiImage({ + double? maxWidth, + double? maxHeight, + int? imageQuality, + }) async { + List? paths = await _pickMultiImagePath( + maxWidth: maxWidth, + maxHeight: maxHeight, + imageQuality: imageQuality, + ); + List files = []; + for (final path in paths!) { + files.add(PickedFile(path)); + } + return files; + } + + Future _pickMultiImagePath({ + double? maxWidth, + double? maxHeight, + int? imageQuality, + }) { + if (imageQuality != null && (imageQuality < 0 || imageQuality > 100)) { + throw ArgumentError.value( + imageQuality, 'imageQuality', 'must be between 0 and 100'); + } + + if (maxWidth != null && maxWidth < 0) { + throw ArgumentError.value(maxWidth, 'maxWidth', 'cannot be negative'); + } + + if (maxHeight != null && maxHeight < 0) { + throw ArgumentError.value(maxHeight, 'maxHeight', 'cannot be negative'); + } + + return _channel.invokeMethod>( + 'pickMultiImage', + { + 'maxWidth': maxWidth, + 'maxHeight': maxHeight, + 'imageQuality': imageQuality, + }, + ); + } + Future _pickImagePath({ required ImageSource source, double? maxWidth, diff --git a/packages/image_picker/image_picker_platform_interface/lib/src/platform_interface/image_picker_platform.dart b/packages/image_picker/image_picker_platform_interface/lib/src/platform_interface/image_picker_platform.dart index 44b85f17f3db..3fabb870affa 100644 --- a/packages/image_picker/image_picker_platform_interface/lib/src/platform_interface/image_picker_platform.dart +++ b/packages/image_picker/image_picker_platform_interface/lib/src/platform_interface/image_picker_platform.dart @@ -54,9 +54,9 @@ abstract class ImagePickerPlatform extends PlatformInterface { /// /// 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 supportted for certain + /// the original quality will be returned. Compression is only supported for certain /// image types such as JPEG. If compression is not supported for the image that is picked, - /// an warning message will be logged. + /// 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. @@ -78,6 +78,32 @@ abstract class ImagePickerPlatform extends PlatformInterface { throw UnimplementedError('pickImage() has not been implemented.'); } + /// Returns a [List] with the images that were picked. + /// + /// The images come from the [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. + /// + /// 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 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. If compression is not supported for the image that is picked, + /// a warning message will be logged. + /// + /// If no images were picked, the return value is null. + Future?> pickMultiImage({ + double? maxWidth, + double? maxHeight, + int? imageQuality, + }) { + throw UnimplementedError('pickMultiImage() has not been implemented.'); + } + /// Returns a [PickedFile] containing the video that was picked. /// /// The [source] argument controls where the video comes from. This can diff --git a/packages/image_picker/image_picker_platform_interface/pubspec.yaml b/packages/image_picker/image_picker_platform_interface/pubspec.yaml index 3443f158dc56..446cf632f9b4 100644 --- a/packages/image_picker/image_picker_platform_interface/pubspec.yaml +++ b/packages/image_picker/image_picker_platform_interface/pubspec.yaml @@ -3,7 +3,7 @@ description: A common platform interface for the image_picker plugin. homepage: https://github.com/flutter/plugins/tree/master/packages/image_picker/image_picker_platform_interface # NOTE: We strongly prefer non-breaking changes, even at the expense of a # less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes -version: 2.0.1 +version: 2.1.1 dependencies: flutter: From d2871f6105a168c9b07fd0ce85e503a8a496c2ea Mon Sep 17 00:00:00 2001 From: "daniel.roek" Date: Wed, 17 Mar 2021 10:06:56 +0100 Subject: [PATCH 2/9] Added tests --- .../method_channel_image_picker.dart | 6 +- .../new_method_channel_image_picker_test.dart | 108 +++++++++++++++++- 2 files changed, 111 insertions(+), 3 deletions(-) diff --git a/packages/image_picker/image_picker_platform_interface/lib/src/method_channel/method_channel_image_picker.dart b/packages/image_picker/image_picker_platform_interface/lib/src/method_channel/method_channel_image_picker.dart index 31847a188d84..6570d4663f0a 100644 --- a/packages/image_picker/image_picker_platform_interface/lib/src/method_channel/method_channel_image_picker.dart +++ b/packages/image_picker/image_picker_platform_interface/lib/src/method_channel/method_channel_image_picker.dart @@ -47,6 +47,8 @@ class MethodChannelImagePicker extends ImagePickerPlatform { maxHeight: maxHeight, imageQuality: imageQuality, ); + if (paths == null) return null; + List files = []; for (final path in paths!) { files.add(PickedFile(path)); @@ -54,7 +56,7 @@ class MethodChannelImagePicker extends ImagePickerPlatform { return files; } - Future _pickMultiImagePath({ + Future?> _pickMultiImagePath({ double? maxWidth, double? maxHeight, int? imageQuality, @@ -72,7 +74,7 @@ class MethodChannelImagePicker extends ImagePickerPlatform { throw ArgumentError.value(maxHeight, 'maxHeight', 'cannot be negative'); } - return _channel.invokeMethod>( + return _channel.invokeMethod?>( 'pickMultiImage', { 'maxWidth': maxWidth, diff --git a/packages/image_picker/image_picker_platform_interface/test/new_method_channel_image_picker_test.dart b/packages/image_picker/image_picker_platform_interface/test/new_method_channel_image_picker_test.dart index df35f8fd96b8..8c3023f82f69 100644 --- a/packages/image_picker/image_picker_platform_interface/test/new_method_channel_image_picker_test.dart +++ b/packages/image_picker/image_picker_platform_interface/test/new_method_channel_image_picker_test.dart @@ -16,7 +16,8 @@ void main() { final List log = []; - setUp(() { + + setUpAll(() { picker.channel.setMockMethodCallHandler((MethodCall methodCall) async { log.add(methodCall); return ''; @@ -196,6 +197,111 @@ void main() { }); }); + group('#pickMultiImage', () { + test('calls the method correctly', () async { + await picker.pickMultiImage(); + + expect( + log, + [ + isMethodCall('pickMultiImage', arguments: { + 'maxWidth': null, + 'maxHeight': null, + 'imageQuality': null, + }), + ], + ); + }); + + test('passes the width and height arguments correctly', () async { + await picker.pickMultiImage(); + await picker.pickMultiImage( + maxWidth: 10.0, + ); + await picker.pickMultiImage( + maxHeight: 10.0, + ); + await picker.pickMultiImage( + maxWidth: 10.0, + maxHeight: 20.0, + ); + await picker.pickMultiImage( + maxWidth: 10.0, + imageQuality: 70, + ); + await picker.pickMultiImage( + maxHeight: 10.0, + imageQuality: 70, + ); + await picker.pickMultiImage( + maxWidth: 10.0, + maxHeight: 20.0, + imageQuality: 70, + ); + + expect( + log, + [ + isMethodCall('pickMultiImage', arguments: { + 'maxWidth': null, + 'maxHeight': null, + 'imageQuality': null, + }), + isMethodCall('pickMultiImage', arguments: { + 'maxWidth': 10.0, + 'maxHeight': null, + 'imageQuality': null, + }), + isMethodCall('pickMultiImage', arguments: { + 'maxWidth': null, + 'maxHeight': 10.0, + 'imageQuality': null, + }), + isMethodCall('pickMultiImage', arguments: { + 'maxWidth': 10.0, + 'maxHeight': 20.0, + 'imageQuality': null, + }), + isMethodCall('pickMultiImage', arguments: { + 'maxWidth': 10.0, + 'maxHeight': null, + 'imageQuality': 70, + }), + isMethodCall('pickMultiImage', arguments: { + 'maxWidth': null, + 'maxHeight': 10.0, + 'imageQuality': 70, + }), + isMethodCall('pickMultiImage', arguments: { + 'maxWidth': 10.0, + 'maxHeight': 20.0, + 'imageQuality': 70, + }), + ], + ); + }); + + test('does not accept a negative width or height argument', () { + expect( + () => picker.pickMultiImage(maxWidth: -1.0), + throwsArgumentError, + ); + + expect( + () => picker.pickMultiImage(maxHeight: -1.0), + throwsArgumentError, + ); + }); + + test('handles a null image path response gracefully', () async { + picker.channel + .setMockMethodCallHandler((MethodCall methodCall) => null); + + expect(await picker.pickMultiImage(), isNull); + expect(await picker.pickMultiImage(), isNull); + }); + }); + group('#pickVideoPath', () { test('passes the image source argument correctly', () async { await picker.pickVideo(source: ImageSource.camera); From 25efcf2da43626fa60de969da7088bf980524a8d Mon Sep 17 00:00:00 2001 From: "daniel.roek" Date: Wed, 17 Mar 2021 10:31:55 +0100 Subject: [PATCH 3/9] fixed platform_interface tests --- .../test/new_method_channel_image_picker_test.dart | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/image_picker/image_picker_platform_interface/test/new_method_channel_image_picker_test.dart b/packages/image_picker/image_picker_platform_interface/test/new_method_channel_image_picker_test.dart index 8c3023f82f69..a4de47df73bc 100644 --- a/packages/image_picker/image_picker_platform_interface/test/new_method_channel_image_picker_test.dart +++ b/packages/image_picker/image_picker_platform_interface/test/new_method_channel_image_picker_test.dart @@ -15,12 +15,12 @@ void main() { MethodChannelImagePicker picker = MethodChannelImagePicker(); final List log = []; + dynamic returnValue = ''; - - setUpAll(() { + setUp(() { picker.channel.setMockMethodCallHandler((MethodCall methodCall) async { log.add(methodCall); - return ''; + return returnValue; }); log.clear(); @@ -199,6 +199,7 @@ void main() { group('#pickMultiImage', () { test('calls the method correctly', () async { + returnValue = ['0', '1']; await picker.pickMultiImage(); expect( @@ -214,6 +215,7 @@ void main() { }); test('passes the width and height arguments correctly', () async { + returnValue = ['0', '1']; await picker.pickMultiImage(); await picker.pickMultiImage( maxWidth: 10.0, @@ -282,6 +284,7 @@ void main() { }); test('does not accept a negative width or height argument', () { + returnValue = ['0', '1']; expect( () => picker.pickMultiImage(maxWidth: -1.0), throwsArgumentError, From 181a52a339a4bebe0a72021d4702e0419e30873d Mon Sep 17 00:00:00 2001 From: Daniel Roek Date: Wed, 17 Mar 2021 10:06:56 +0100 Subject: [PATCH 4/9] Added tests --- .../method_channel_image_picker.dart | 10 +- .../new_method_channel_image_picker_test.dart | 108 +++++++++++++++++- 2 files changed, 113 insertions(+), 5 deletions(-) diff --git a/packages/image_picker/image_picker_platform_interface/lib/src/method_channel/method_channel_image_picker.dart b/packages/image_picker/image_picker_platform_interface/lib/src/method_channel/method_channel_image_picker.dart index 31847a188d84..ca7da8f8dc1e 100644 --- a/packages/image_picker/image_picker_platform_interface/lib/src/method_channel/method_channel_image_picker.dart +++ b/packages/image_picker/image_picker_platform_interface/lib/src/method_channel/method_channel_image_picker.dart @@ -42,19 +42,21 @@ class MethodChannelImagePicker extends ImagePickerPlatform { double? maxHeight, int? imageQuality, }) async { - List? paths = await _pickMultiImagePath( + List? paths = await _pickMultiImagePath( maxWidth: maxWidth, maxHeight: maxHeight, imageQuality: imageQuality, ); + if (paths == null) return null; + List files = []; - for (final path in paths!) { + for (final path in paths) { files.add(PickedFile(path)); } return files; } - Future _pickMultiImagePath({ + Future?> _pickMultiImagePath({ double? maxWidth, double? maxHeight, int? imageQuality, @@ -72,7 +74,7 @@ class MethodChannelImagePicker extends ImagePickerPlatform { throw ArgumentError.value(maxHeight, 'maxHeight', 'cannot be negative'); } - return _channel.invokeMethod>( + return _channel.invokeMethod?>( 'pickMultiImage', { 'maxWidth': maxWidth, diff --git a/packages/image_picker/image_picker_platform_interface/test/new_method_channel_image_picker_test.dart b/packages/image_picker/image_picker_platform_interface/test/new_method_channel_image_picker_test.dart index df35f8fd96b8..8c3023f82f69 100644 --- a/packages/image_picker/image_picker_platform_interface/test/new_method_channel_image_picker_test.dart +++ b/packages/image_picker/image_picker_platform_interface/test/new_method_channel_image_picker_test.dart @@ -16,7 +16,8 @@ void main() { final List log = []; - setUp(() { + + setUpAll(() { picker.channel.setMockMethodCallHandler((MethodCall methodCall) async { log.add(methodCall); return ''; @@ -196,6 +197,111 @@ void main() { }); }); + group('#pickMultiImage', () { + test('calls the method correctly', () async { + await picker.pickMultiImage(); + + expect( + log, + [ + isMethodCall('pickMultiImage', arguments: { + 'maxWidth': null, + 'maxHeight': null, + 'imageQuality': null, + }), + ], + ); + }); + + test('passes the width and height arguments correctly', () async { + await picker.pickMultiImage(); + await picker.pickMultiImage( + maxWidth: 10.0, + ); + await picker.pickMultiImage( + maxHeight: 10.0, + ); + await picker.pickMultiImage( + maxWidth: 10.0, + maxHeight: 20.0, + ); + await picker.pickMultiImage( + maxWidth: 10.0, + imageQuality: 70, + ); + await picker.pickMultiImage( + maxHeight: 10.0, + imageQuality: 70, + ); + await picker.pickMultiImage( + maxWidth: 10.0, + maxHeight: 20.0, + imageQuality: 70, + ); + + expect( + log, + [ + isMethodCall('pickMultiImage', arguments: { + 'maxWidth': null, + 'maxHeight': null, + 'imageQuality': null, + }), + isMethodCall('pickMultiImage', arguments: { + 'maxWidth': 10.0, + 'maxHeight': null, + 'imageQuality': null, + }), + isMethodCall('pickMultiImage', arguments: { + 'maxWidth': null, + 'maxHeight': 10.0, + 'imageQuality': null, + }), + isMethodCall('pickMultiImage', arguments: { + 'maxWidth': 10.0, + 'maxHeight': 20.0, + 'imageQuality': null, + }), + isMethodCall('pickMultiImage', arguments: { + 'maxWidth': 10.0, + 'maxHeight': null, + 'imageQuality': 70, + }), + isMethodCall('pickMultiImage', arguments: { + 'maxWidth': null, + 'maxHeight': 10.0, + 'imageQuality': 70, + }), + isMethodCall('pickMultiImage', arguments: { + 'maxWidth': 10.0, + 'maxHeight': 20.0, + 'imageQuality': 70, + }), + ], + ); + }); + + test('does not accept a negative width or height argument', () { + expect( + () => picker.pickMultiImage(maxWidth: -1.0), + throwsArgumentError, + ); + + expect( + () => picker.pickMultiImage(maxHeight: -1.0), + throwsArgumentError, + ); + }); + + test('handles a null image path response gracefully', () async { + picker.channel + .setMockMethodCallHandler((MethodCall methodCall) => null); + + expect(await picker.pickMultiImage(), isNull); + expect(await picker.pickMultiImage(), isNull); + }); + }); + group('#pickVideoPath', () { test('passes the image source argument correctly', () async { await picker.pickVideo(source: ImageSource.camera); From 7568874d62aad235804ea302a1e48b4aaf659d75 Mon Sep 17 00:00:00 2001 From: "daniel.roek" Date: Wed, 17 Mar 2021 10:31:55 +0100 Subject: [PATCH 5/9] fixed platform_interface tests --- .../test/new_method_channel_image_picker_test.dart | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/image_picker/image_picker_platform_interface/test/new_method_channel_image_picker_test.dart b/packages/image_picker/image_picker_platform_interface/test/new_method_channel_image_picker_test.dart index 8c3023f82f69..a4de47df73bc 100644 --- a/packages/image_picker/image_picker_platform_interface/test/new_method_channel_image_picker_test.dart +++ b/packages/image_picker/image_picker_platform_interface/test/new_method_channel_image_picker_test.dart @@ -15,12 +15,12 @@ void main() { MethodChannelImagePicker picker = MethodChannelImagePicker(); final List log = []; + dynamic returnValue = ''; - - setUpAll(() { + setUp(() { picker.channel.setMockMethodCallHandler((MethodCall methodCall) async { log.add(methodCall); - return ''; + return returnValue; }); log.clear(); @@ -199,6 +199,7 @@ void main() { group('#pickMultiImage', () { test('calls the method correctly', () async { + returnValue = ['0', '1']; await picker.pickMultiImage(); expect( @@ -214,6 +215,7 @@ void main() { }); test('passes the width and height arguments correctly', () async { + returnValue = ['0', '1']; await picker.pickMultiImage(); await picker.pickMultiImage( maxWidth: 10.0, @@ -282,6 +284,7 @@ void main() { }); test('does not accept a negative width or height argument', () { + returnValue = ['0', '1']; expect( () => picker.pickMultiImage(maxWidth: -1.0), throwsArgumentError, From a9d8eb9eab9a2bd61a6950199852a2d99a071b8f Mon Sep 17 00:00:00 2001 From: Daniel Roek Date: Fri, 2 Apr 2021 12:27:07 +0200 Subject: [PATCH 6/9] Fixed tests --- .../test/new_method_channel_image_picker_test.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/image_picker/image_picker_platform_interface/test/new_method_channel_image_picker_test.dart b/packages/image_picker/image_picker_platform_interface/test/new_method_channel_image_picker_test.dart index a4de47df73bc..e12572248608 100644 --- a/packages/image_picker/image_picker_platform_interface/test/new_method_channel_image_picker_test.dart +++ b/packages/image_picker/image_picker_platform_interface/test/new_method_channel_image_picker_test.dart @@ -18,6 +18,7 @@ void main() { dynamic returnValue = ''; setUp(() { + returnValue = ''; picker.channel.setMockMethodCallHandler((MethodCall methodCall) async { log.add(methodCall); return returnValue; From db47a34dad79166a53d4a3fd356237a0f525330a Mon Sep 17 00:00:00 2001 From: Daniel Roek Date: Fri, 2 Apr 2021 12:48:13 +0200 Subject: [PATCH 7/9] Fixed version in pubspec.yaml --- .../image_picker/image_picker_platform_interface/CHANGELOG.md | 2 +- .../image_picker/image_picker_platform_interface/pubspec.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/image_picker/image_picker_platform_interface/CHANGELOG.md b/packages/image_picker/image_picker_platform_interface/CHANGELOG.md index 266654eff6fc..8375ea774c8d 100644 --- a/packages/image_picker/image_picker_platform_interface/CHANGELOG.md +++ b/packages/image_picker/image_picker_platform_interface/CHANGELOG.md @@ -1,6 +1,6 @@ ## 2.1.0 -* Added pickMultiImage call +* Added pickMultiImage method ## 2.0.1 diff --git a/packages/image_picker/image_picker_platform_interface/pubspec.yaml b/packages/image_picker/image_picker_platform_interface/pubspec.yaml index 446cf632f9b4..bd197a6f194c 100644 --- a/packages/image_picker/image_picker_platform_interface/pubspec.yaml +++ b/packages/image_picker/image_picker_platform_interface/pubspec.yaml @@ -3,7 +3,7 @@ description: A common platform interface for the image_picker plugin. homepage: https://github.com/flutter/plugins/tree/master/packages/image_picker/image_picker_platform_interface # NOTE: We strongly prefer non-breaking changes, even at the expense of a # less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes -version: 2.1.1 +version: 2.1.0 dependencies: flutter: From bd98080891e011d03b6aa359e4b7b94d889d1e4e Mon Sep 17 00:00:00 2001 From: "daniel.roek" Date: Fri, 9 Apr 2021 10:52:59 +0200 Subject: [PATCH 8/9] Added test for imageQuality value; Implemented feedback --- .../CHANGELOG.md | 2 +- .../method_channel_image_picker.dart | 6 ++-- .../new_method_channel_image_picker_test.dart | 36 +++++++++++++++++++ 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/packages/image_picker/image_picker_platform_interface/CHANGELOG.md b/packages/image_picker/image_picker_platform_interface/CHANGELOG.md index 8375ea774c8d..e2def7243592 100644 --- a/packages/image_picker/image_picker_platform_interface/CHANGELOG.md +++ b/packages/image_picker/image_picker_platform_interface/CHANGELOG.md @@ -1,6 +1,6 @@ ## 2.1.0 -* Added pickMultiImage method +* Add `pickMultiImage` method. ## 2.0.1 diff --git a/packages/image_picker/image_picker_platform_interface/lib/src/method_channel/method_channel_image_picker.dart b/packages/image_picker/image_picker_platform_interface/lib/src/method_channel/method_channel_image_picker.dart index d834ebea1d65..e0f46457a8b8 100644 --- a/packages/image_picker/image_picker_platform_interface/lib/src/method_channel/method_channel_image_picker.dart +++ b/packages/image_picker/image_picker_platform_interface/lib/src/method_channel/method_channel_image_picker.dart @@ -42,14 +42,14 @@ class MethodChannelImagePicker extends ImagePickerPlatform { double? maxHeight, int? imageQuality, }) async { - List? paths = await _pickMultiImagePath( + final List? paths = await _pickMultiImagePath( maxWidth: maxWidth, maxHeight: maxHeight, imageQuality: imageQuality, ); if (paths == null) return null; - List files = []; + final List files = []; for (final path in paths) { files.add(PickedFile(path)); } @@ -122,7 +122,7 @@ class MethodChannelImagePicker extends ImagePickerPlatform { CameraDevice preferredCameraDevice = CameraDevice.rear, Duration? maxDuration, }) async { - String? path = await _pickVideoPath( + final String? path = await _pickVideoPath( source: source, maxDuration: maxDuration, preferredCameraDevice: preferredCameraDevice, diff --git a/packages/image_picker/image_picker_platform_interface/test/new_method_channel_image_picker_test.dart b/packages/image_picker/image_picker_platform_interface/test/new_method_channel_image_picker_test.dart index 9256a0a2f576..bdf6199c3b26 100644 --- a/packages/image_picker/image_picker_platform_interface/test/new_method_channel_image_picker_test.dart +++ b/packages/image_picker/image_picker_platform_interface/test/new_method_channel_image_picker_test.dart @@ -141,6 +141,29 @@ void main() { ); }); + test('does not accept a invalid imageQuality argument', () { + expect( + () => picker.pickImage(imageQuality: -1, source: ImageSource.gallery), + throwsArgumentError, + ); + + expect( + () => picker.pickImage(imageQuality: 101, source: ImageSource.gallery), + throwsArgumentError, + ); + + expect( + () => picker.pickImage(imageQuality: -1, source: ImageSource.camera), + throwsArgumentError, + ); + + expect( + () => picker.pickImage(imageQuality: 101, source: ImageSource.camera), + throwsArgumentError, + ); + }); + + test('does not accept a negative width or height argument', () { expect( () => picker.pickImage(source: ImageSource.camera, maxWidth: -1.0), @@ -297,6 +320,19 @@ void main() { ); }); + test('does not accept a invalid imageQuality argument', () { + returnValue = ['0', '1']; + expect( + () => picker.pickMultiImage(imageQuality: -1), + throwsArgumentError, + ); + + expect( + () => picker.pickMultiImage(imageQuality: 101), + throwsArgumentError, + ); + }); + test('handles a null image path response gracefully', () async { picker.channel .setMockMethodCallHandler((MethodCall methodCall) => null); From 07801fc0c9bf070fc52f0e109dcac7d362c9a576 Mon Sep 17 00:00:00 2001 From: "daniel.roek" Date: Fri, 9 Apr 2021 10:57:46 +0200 Subject: [PATCH 9/9] Format --- .../new_method_channel_image_picker_test.dart | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/image_picker/image_picker_platform_interface/test/new_method_channel_image_picker_test.dart b/packages/image_picker/image_picker_platform_interface/test/new_method_channel_image_picker_test.dart index bdf6199c3b26..83ae6fac9071 100644 --- a/packages/image_picker/image_picker_platform_interface/test/new_method_channel_image_picker_test.dart +++ b/packages/image_picker/image_picker_platform_interface/test/new_method_channel_image_picker_test.dart @@ -143,27 +143,27 @@ void main() { test('does not accept a invalid imageQuality argument', () { expect( - () => picker.pickImage(imageQuality: -1, source: ImageSource.gallery), + () => picker.pickImage(imageQuality: -1, source: ImageSource.gallery), throwsArgumentError, ); expect( - () => picker.pickImage(imageQuality: 101, source: ImageSource.gallery), + () => + picker.pickImage(imageQuality: 101, source: ImageSource.gallery), throwsArgumentError, ); expect( - () => picker.pickImage(imageQuality: -1, source: ImageSource.camera), + () => picker.pickImage(imageQuality: -1, source: ImageSource.camera), throwsArgumentError, ); expect( - () => picker.pickImage(imageQuality: 101, source: ImageSource.camera), + () => picker.pickImage(imageQuality: 101, source: ImageSource.camera), throwsArgumentError, ); }); - test('does not accept a negative width or height argument', () { expect( () => picker.pickImage(source: ImageSource.camera, maxWidth: -1.0), @@ -320,9 +320,9 @@ void main() { ); }); - test('does not accept a invalid imageQuality argument', () { - returnValue = ['0', '1']; - expect( + test('does not accept a invalid imageQuality argument', () { + returnValue = ['0', '1']; + expect( () => picker.pickMultiImage(imageQuality: -1), throwsArgumentError, );