diff --git a/packages/image_picker/image_picker_android/pigeons/messages.dart b/packages/image_picker/image_picker_android/pigeons/messages.dart index f6e74c1251b..940e4650eab 100644 --- a/packages/image_picker/image_picker_android/pigeons/messages.dart +++ b/packages/image_picker/image_picker_android/pigeons/messages.dart @@ -7,7 +7,6 @@ import 'package:pigeon/pigeon.dart'; @ConfigurePigeon( PigeonOptions( dartOut: 'lib/src/messages.g.dart', - dartTestOut: 'test/test_api.g.dart', javaOut: 'android/src/main/java/io/flutter/plugins/imagepicker/Messages.java', javaOptions: JavaOptions(package: 'io.flutter.plugins.imagepicker'), @@ -94,7 +93,7 @@ class CacheRetrievalResult { final List paths; } -@HostApi(dartHostTestHandler: 'TestHostImagePickerApi') +@HostApi() abstract class ImagePickerApi { /// Selects images and returns their paths. @TaskQueue(type: TaskQueueType.serialBackgroundThread) diff --git a/packages/image_picker/image_picker_android/test/test_api.g.dart b/packages/image_picker/image_picker_android/test/test_api.g.dart deleted file mode 100644 index 749a03a0060..00000000000 --- a/packages/image_picker/image_picker_android/test/test_api.g.dart +++ /dev/null @@ -1,313 +0,0 @@ -// Copyright 2013 The Flutter Authors -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// Autogenerated from Pigeon (v24.2.0), do not edit directly. -// See also: https://pub.dev/packages/pigeon -// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, unnecessary_import, no_leading_underscores_for_local_identifiers -// ignore_for_file: avoid_relative_lib_imports -import 'dart:async'; -import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; -import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; -import 'package:flutter/services.dart'; -import 'package:flutter_test/flutter_test.dart'; - -import 'package:image_picker_android/src/messages.g.dart'; - -class _PigeonCodec extends StandardMessageCodec { - const _PigeonCodec(); - @override - void writeValue(WriteBuffer buffer, Object? value) { - if (value is int) { - buffer.putUint8(4); - buffer.putInt64(value); - } else if (value is SourceCamera) { - buffer.putUint8(129); - writeValue(buffer, value.index); - } else if (value is SourceType) { - buffer.putUint8(130); - writeValue(buffer, value.index); - } else if (value is CacheRetrievalType) { - buffer.putUint8(131); - writeValue(buffer, value.index); - } else if (value is GeneralOptions) { - buffer.putUint8(132); - writeValue(buffer, value.encode()); - } else if (value is ImageSelectionOptions) { - buffer.putUint8(133); - writeValue(buffer, value.encode()); - } else if (value is MediaSelectionOptions) { - buffer.putUint8(134); - writeValue(buffer, value.encode()); - } else if (value is VideoSelectionOptions) { - buffer.putUint8(135); - writeValue(buffer, value.encode()); - } else if (value is SourceSpecification) { - buffer.putUint8(136); - writeValue(buffer, value.encode()); - } else if (value is CacheRetrievalError) { - buffer.putUint8(137); - writeValue(buffer, value.encode()); - } else if (value is CacheRetrievalResult) { - buffer.putUint8(138); - writeValue(buffer, value.encode()); - } else { - super.writeValue(buffer, value); - } - } - - @override - Object? readValueOfType(int type, ReadBuffer buffer) { - switch (type) { - case 129: - final int? value = readValue(buffer) as int?; - return value == null ? null : SourceCamera.values[value]; - case 130: - final int? value = readValue(buffer) as int?; - return value == null ? null : SourceType.values[value]; - case 131: - final int? value = readValue(buffer) as int?; - return value == null ? null : CacheRetrievalType.values[value]; - case 132: - return GeneralOptions.decode(readValue(buffer)!); - case 133: - return ImageSelectionOptions.decode(readValue(buffer)!); - case 134: - return MediaSelectionOptions.decode(readValue(buffer)!); - case 135: - return VideoSelectionOptions.decode(readValue(buffer)!); - case 136: - return SourceSpecification.decode(readValue(buffer)!); - case 137: - return CacheRetrievalError.decode(readValue(buffer)!); - case 138: - return CacheRetrievalResult.decode(readValue(buffer)!); - default: - return super.readValueOfType(type, buffer); - } - } -} - -abstract class TestHostImagePickerApi { - static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => - TestDefaultBinaryMessengerBinding.instance; - static const MessageCodec pigeonChannelCodec = _PigeonCodec(); - - /// Selects images and returns their paths. - Future> pickImages( - SourceSpecification source, - ImageSelectionOptions options, - GeneralOptions generalOptions, - ); - - /// Selects video and returns their paths. - Future> pickVideos( - SourceSpecification source, - VideoSelectionOptions options, - GeneralOptions generalOptions, - ); - - /// Selects images and videos and returns their paths. - Future> pickMedia( - MediaSelectionOptions mediaSelectionOptions, - GeneralOptions generalOptions, - ); - - /// Returns results from a previous app session, if any. - CacheRetrievalResult? retrieveLostResults(); - - static void setUp( - TestHostImagePickerApi? api, { - BinaryMessenger? binaryMessenger, - String messageChannelSuffix = '', - }) { - messageChannelSuffix = messageChannelSuffix.isNotEmpty - ? '.$messageChannelSuffix' - : ''; - { - final BasicMessageChannel - pigeonVar_channel = BasicMessageChannel( - 'dev.flutter.pigeon.image_picker_android.ImagePickerApi.pickImages$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger, - ); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler< - Object? - >(pigeonVar_channel, (Object? message) async { - assert( - message != null, - 'Argument for dev.flutter.pigeon.image_picker_android.ImagePickerApi.pickImages was null.', - ); - final List args = (message as List?)!; - final SourceSpecification? arg_source = - (args[0] as SourceSpecification?); - assert( - arg_source != null, - 'Argument for dev.flutter.pigeon.image_picker_android.ImagePickerApi.pickImages was null, expected non-null SourceSpecification.', - ); - final ImageSelectionOptions? arg_options = - (args[1] as ImageSelectionOptions?); - assert( - arg_options != null, - 'Argument for dev.flutter.pigeon.image_picker_android.ImagePickerApi.pickImages was null, expected non-null ImageSelectionOptions.', - ); - final GeneralOptions? arg_generalOptions = - (args[2] as GeneralOptions?); - assert( - arg_generalOptions != null, - 'Argument for dev.flutter.pigeon.image_picker_android.ImagePickerApi.pickImages was null, expected non-null GeneralOptions.', - ); - try { - final List output = await api.pickImages( - arg_source!, - arg_options!, - arg_generalOptions!, - ); - return [output]; - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString()), - ); - } - }); - } - } - { - final BasicMessageChannel - pigeonVar_channel = BasicMessageChannel( - 'dev.flutter.pigeon.image_picker_android.ImagePickerApi.pickVideos$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger, - ); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler< - Object? - >(pigeonVar_channel, (Object? message) async { - assert( - message != null, - 'Argument for dev.flutter.pigeon.image_picker_android.ImagePickerApi.pickVideos was null.', - ); - final List args = (message as List?)!; - final SourceSpecification? arg_source = - (args[0] as SourceSpecification?); - assert( - arg_source != null, - 'Argument for dev.flutter.pigeon.image_picker_android.ImagePickerApi.pickVideos was null, expected non-null SourceSpecification.', - ); - final VideoSelectionOptions? arg_options = - (args[1] as VideoSelectionOptions?); - assert( - arg_options != null, - 'Argument for dev.flutter.pigeon.image_picker_android.ImagePickerApi.pickVideos was null, expected non-null VideoSelectionOptions.', - ); - final GeneralOptions? arg_generalOptions = - (args[2] as GeneralOptions?); - assert( - arg_generalOptions != null, - 'Argument for dev.flutter.pigeon.image_picker_android.ImagePickerApi.pickVideos was null, expected non-null GeneralOptions.', - ); - try { - final List output = await api.pickVideos( - arg_source!, - arg_options!, - arg_generalOptions!, - ); - return [output]; - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString()), - ); - } - }); - } - } - { - final BasicMessageChannel - pigeonVar_channel = BasicMessageChannel( - 'dev.flutter.pigeon.image_picker_android.ImagePickerApi.pickMedia$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger, - ); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler< - Object? - >(pigeonVar_channel, (Object? message) async { - assert( - message != null, - 'Argument for dev.flutter.pigeon.image_picker_android.ImagePickerApi.pickMedia was null.', - ); - final List args = (message as List?)!; - final MediaSelectionOptions? arg_mediaSelectionOptions = - (args[0] as MediaSelectionOptions?); - assert( - arg_mediaSelectionOptions != null, - 'Argument for dev.flutter.pigeon.image_picker_android.ImagePickerApi.pickMedia was null, expected non-null MediaSelectionOptions.', - ); - final GeneralOptions? arg_generalOptions = - (args[1] as GeneralOptions?); - assert( - arg_generalOptions != null, - 'Argument for dev.flutter.pigeon.image_picker_android.ImagePickerApi.pickMedia was null, expected non-null GeneralOptions.', - ); - try { - final List output = await api.pickMedia( - arg_mediaSelectionOptions!, - arg_generalOptions!, - ); - return [output]; - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString()), - ); - } - }); - } - } - { - final BasicMessageChannel - pigeonVar_channel = BasicMessageChannel( - 'dev.flutter.pigeon.image_picker_android.ImagePickerApi.retrieveLostResults$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger, - ); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, ( - Object? message, - ) async { - try { - final CacheRetrievalResult? output = api.retrieveLostResults(); - return [output]; - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException( - code: 'error', - message: e.toString(), - ), - ); - } - }); - } - } - } -} diff --git a/packages/image_picker/image_picker_ios/lib/image_picker_ios.dart b/packages/image_picker/image_picker_ios/lib/image_picker_ios.dart index 7d58aa8e3b7..fa373a31bb0 100644 --- a/packages/image_picker/image_picker_ios/lib/image_picker_ios.dart +++ b/packages/image_picker/image_picker_ios/lib/image_picker_ios.dart @@ -3,6 +3,7 @@ // found in the LICENSE file. import 'dart:async'; +import 'package:flutter/foundation.dart' show visibleForTesting; import 'package:image_picker_platform_interface/image_picker_platform_interface.dart'; import 'src/messages.g.dart'; @@ -43,7 +44,11 @@ SourceCamera _convertCamera(CameraDevice camera) { /// An implementation of [ImagePickerPlatform] for iOS. class ImagePickerIOS extends ImagePickerPlatform { - final ImagePickerApi _hostApi = ImagePickerApi(); + /// Creates a new plugin implementation instance. + ImagePickerIOS({@visibleForTesting ImagePickerApi? api}) + : _hostApi = api ?? ImagePickerApi(); + + final ImagePickerApi _hostApi; /// Registers this class as the default platform implementation. static void registerWith() { diff --git a/packages/image_picker/image_picker_ios/pigeons/messages.dart b/packages/image_picker/image_picker_ios/pigeons/messages.dart index 773e09591ad..a52653380a2 100644 --- a/packages/image_picker/image_picker_ios/pigeons/messages.dart +++ b/packages/image_picker/image_picker_ios/pigeons/messages.dart @@ -7,7 +7,6 @@ import 'package:pigeon/pigeon.dart'; @ConfigurePigeon( PigeonOptions( dartOut: 'lib/src/messages.g.dart', - dartTestOut: 'test/test_api.g.dart', objcHeaderOut: 'ios/image_picker_ios/Sources/image_picker_ios/include/image_picker_ios/messages.g.h', objcSourceOut: 'ios/image_picker_ios/Sources/image_picker_ios/messages.g.m', @@ -52,7 +51,7 @@ class SourceSpecification { SourceCamera camera; } -@HostApi(dartHostTestHandler: 'TestHostImagePickerApi') +@HostApi() abstract class ImagePickerApi { @async @ObjCSelector('pickImageWithSource:maxSize:quality:fullMetadata:') diff --git a/packages/image_picker/image_picker_ios/test/image_picker_ios_test.dart b/packages/image_picker/image_picker_ios/test/image_picker_ios_test.dart index 2b8edac2bf9..d423acd05de 100644 --- a/packages/image_picker/image_picker_ios/test/image_picker_ios_test.dart +++ b/packages/image_picker/image_picker_ios/test/image_picker_ios_test.dart @@ -2,152 +2,21 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'package:flutter/foundation.dart'; +import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:image_picker_ios/image_picker_ios.dart'; import 'package:image_picker_ios/src/messages.g.dart'; import 'package:image_picker_platform_interface/image_picker_platform_interface.dart'; -import 'test_api.g.dart'; - -@immutable -class _LoggedMethodCall { - const _LoggedMethodCall(this.name, {required this.arguments}); - final String name; - final Map arguments; - - @override - bool operator ==(Object other) { - return other is _LoggedMethodCall && - name == other.name && - mapEquals(arguments, other.arguments); - } - - @override - int get hashCode => Object.hash(name, arguments); - - @override - String toString() { - return 'MethodCall: $name $arguments'; - } -} - -class _ApiLogger implements TestHostImagePickerApi { - // The value to return from future calls. - dynamic returnValue = ''; - final List<_LoggedMethodCall> calls = <_LoggedMethodCall>[]; - - @override - Future pickImage( - SourceSpecification source, - MaxSize maxSize, - int? imageQuality, - bool requestFullMetadata, - ) async { - // Flatten arguments for easy comparison. - calls.add( - _LoggedMethodCall( - 'pickImage', - arguments: { - 'source': source.type, - 'cameraDevice': source.camera, - 'maxWidth': maxSize.width, - 'maxHeight': maxSize.height, - 'imageQuality': imageQuality, - 'requestFullMetadata': requestFullMetadata, - }, - ), - ); - return returnValue as String?; - } - - @override - Future> pickMultiImage( - MaxSize maxSize, - int? imageQuality, - bool requestFullMetadata, - int? limit, - ) async { - calls.add( - _LoggedMethodCall( - 'pickMultiImage', - arguments: { - 'maxWidth': maxSize.width, - 'maxHeight': maxSize.height, - 'imageQuality': imageQuality, - 'requestFullMetadata': requestFullMetadata, - 'limit': limit, - }, - ), - ); - return returnValue as List; - } - - @override - Future> pickMedia( - MediaSelectionOptions mediaSelectionOptions, - ) async { - calls.add( - _LoggedMethodCall( - 'pickMedia', - arguments: { - 'maxWidth': mediaSelectionOptions.maxSize.width, - 'maxHeight': mediaSelectionOptions.maxSize.height, - 'imageQuality': mediaSelectionOptions.imageQuality, - 'requestFullMetadata': mediaSelectionOptions.requestFullMetadata, - 'allowMultiple': mediaSelectionOptions.allowMultiple, - 'limit': mediaSelectionOptions.limit, - }, - ), - ); - return returnValue as List; - } - - @override - Future pickVideo( - SourceSpecification source, - int? maxDurationSeconds, - ) async { - calls.add( - _LoggedMethodCall( - 'pickVideo', - arguments: { - 'source': source.type, - 'cameraDevice': source.camera, - 'maxDuration': maxDurationSeconds, - }, - ), - ); - return returnValue as String?; - } - - @override - Future> pickMultiVideo( - int? maxDurationSeconds, - int? limit, - ) async { - calls.add( - _LoggedMethodCall( - 'pickMultiVideo', - arguments: { - 'maxDuration': maxDurationSeconds, - 'limit': limit, - }, - ), - ); - return returnValue as List; - } -} - void main() { TestWidgetsFlutterBinding.ensureInitialized(); - final ImagePickerIOS picker = ImagePickerIOS(); - late _ApiLogger log; + late ImagePickerIOS picker; + late _FakeImagePickerApi api; setUp(() { - log = _ApiLogger(); - TestHostImagePickerApi.setUp(log); + api = _FakeImagePickerApi(); + picker = ImagePickerIOS(api: api); }); test('registration', () async { @@ -156,141 +25,48 @@ void main() { }); group('#pickImage', () { - test('passes the image source argument correctly', () async { + test('calls the method correctly with default arguments', () async { + api.returnValue = ['/foo.png']; + final PickedFile? result = await picker.pickImage( + source: ImageSource.camera, + ); + + expect(result?.path, '/foo.png'); + expect(api.passedSelectionType, _SelectionType.image); + expect(api.passedMaxSize?.width, null); + expect(api.passedMaxSize?.height, null); + expect(api.passedImageQuality, null); + expect(api.passedSource?.camera, SourceCamera.rear); + expect(api.passedRequestFullMetadata, true); + }); + + test('passes camera source argument correctly', () async { await picker.pickImage(source: ImageSource.camera); + + expect(api.passedSource?.type, SourceType.camera); + }); + + test('passes gallery source argument correctly', () async { await picker.pickImage(source: ImageSource.gallery); - expect(log.calls, <_LoggedMethodCall>[ - const _LoggedMethodCall( - 'pickImage', - arguments: { - 'source': SourceType.camera, - 'maxWidth': null, - 'maxHeight': null, - 'imageQuality': null, - 'cameraDevice': SourceCamera.rear, - 'requestFullMetadata': true, - }, - ), - const _LoggedMethodCall( - 'pickImage', - arguments: { - 'source': SourceType.gallery, - 'maxWidth': null, - 'maxHeight': null, - 'imageQuality': null, - 'cameraDevice': SourceCamera.rear, - 'requestFullMetadata': true, - }, - ), - ]); + expect(api.passedSource?.type, SourceType.gallery); }); - test('passes the width and height arguments correctly', () async { - await picker.pickImage(source: ImageSource.camera); - await picker.pickImage(source: ImageSource.camera, maxWidth: 10.0); - await picker.pickImage(source: ImageSource.camera, maxHeight: 10.0); + test('passes width and height arguments correctly', () async { await picker.pickImage( source: ImageSource.camera, maxWidth: 10.0, maxHeight: 20.0, ); - await picker.pickImage( - source: ImageSource.camera, - maxWidth: 10.0, - imageQuality: 70, - ); - await picker.pickImage( - source: ImageSource.camera, - maxHeight: 10.0, - imageQuality: 70, - ); - await picker.pickImage( - source: ImageSource.camera, - maxWidth: 10.0, - maxHeight: 20.0, - imageQuality: 70, - ); - - expect(log.calls, <_LoggedMethodCall>[ - const _LoggedMethodCall( - 'pickImage', - arguments: { - 'source': SourceType.camera, - 'maxWidth': null, - 'maxHeight': null, - 'imageQuality': null, - 'cameraDevice': SourceCamera.rear, - 'requestFullMetadata': true, - }, - ), - const _LoggedMethodCall( - 'pickImage', - arguments: { - 'source': SourceType.camera, - 'maxWidth': 10.0, - 'maxHeight': null, - 'imageQuality': null, - 'cameraDevice': SourceCamera.rear, - 'requestFullMetadata': true, - }, - ), - const _LoggedMethodCall( - 'pickImage', - arguments: { - 'source': SourceType.camera, - 'maxWidth': null, - 'maxHeight': 10.0, - 'imageQuality': null, - 'cameraDevice': SourceCamera.rear, - 'requestFullMetadata': true, - }, - ), - const _LoggedMethodCall( - 'pickImage', - arguments: { - 'source': SourceType.camera, - 'maxWidth': 10.0, - 'maxHeight': 20.0, - 'imageQuality': null, - 'cameraDevice': SourceCamera.rear, - 'requestFullMetadata': true, - }, - ), - const _LoggedMethodCall( - 'pickImage', - arguments: { - 'source': SourceType.camera, - 'maxWidth': 10.0, - 'maxHeight': null, - 'imageQuality': 70, - 'cameraDevice': SourceCamera.rear, - 'requestFullMetadata': true, - }, - ), - const _LoggedMethodCall( - 'pickImage', - arguments: { - 'source': SourceType.camera, - 'maxWidth': null, - 'maxHeight': 10.0, - 'imageQuality': 70, - 'cameraDevice': SourceCamera.rear, - 'requestFullMetadata': true, - }, - ), - const _LoggedMethodCall( - 'pickImage', - arguments: { - 'source': SourceType.camera, - 'maxWidth': 10.0, - 'maxHeight': 20.0, - 'imageQuality': 70, - 'cameraDevice': SourceCamera.rear, - 'requestFullMetadata': true, - }, - ), - ]); + + expect(api.passedMaxSize?.width, 10); + expect(api.passedMaxSize?.height, 20); + }); + + test('passes image quality correctly', () async { + await picker.pickImage(source: ImageSource.camera, imageQuality: 70); + + expect(api.passedImageQuality, 70); }); test('does not accept an invalid imageQuality argument', () { @@ -328,28 +104,9 @@ void main() { }); test('handles a null image path response gracefully', () async { - log.returnValue = null; + api.returnValue = []; expect(await picker.pickImage(source: ImageSource.gallery), isNull); - expect(await picker.pickImage(source: ImageSource.camera), isNull); - }); - - test('camera position defaults to back', () async { - await picker.pickImage(source: ImageSource.camera); - - expect(log.calls, <_LoggedMethodCall>[ - const _LoggedMethodCall( - 'pickImage', - arguments: { - 'source': SourceType.camera, - 'maxWidth': null, - 'maxHeight': null, - 'imageQuality': null, - 'cameraDevice': SourceCamera.rear, - 'requestFullMetadata': true, - }, - ), - ]); }); test('camera position can set to front', () async { @@ -358,127 +115,31 @@ void main() { preferredCameraDevice: CameraDevice.front, ); - expect(log.calls, <_LoggedMethodCall>[ - const _LoggedMethodCall( - 'pickImage', - arguments: { - 'source': SourceType.camera, - 'maxWidth': null, - 'maxHeight': null, - 'imageQuality': null, - 'cameraDevice': SourceCamera.front, - 'requestFullMetadata': true, - }, - ), - ]); + expect(api.passedSource?.camera, SourceCamera.front); }); }); group('#pickMultiImage', () { - test('calls the method correctly', () async { - log.returnValue = ['0', '1']; - await picker.pickMultiImage(); - - expect(log.calls, <_LoggedMethodCall>[ - const _LoggedMethodCall( - 'pickMultiImage', - arguments: { - 'maxWidth': null, - 'maxHeight': null, - 'imageQuality': null, - 'requestFullMetadata': true, - 'limit': null, - }, - ), - ]); + test('calls the method correctly with default arguments', () async { + api.returnValue = ['/foo.png', '/bar.png']; + final List? result = await picker.pickMultiImage(); + + expect(result?.length, 2); + expect(result?[0].path, '/foo.png'); + expect(result?[1].path, '/bar.png'); + expect(api.passedSelectionType, _SelectionType.multiImage); + expect(api.passedRequestFullMetadata, true); + expect(api.passedMaxSize?.width, null); + expect(api.passedMaxSize?.height, null); + expect(api.passedImageQuality, null); + expect(api.passedLimit, null); }); test('passes the width and height arguments correctly', () async { - log.returnValue = ['0', '1']; - 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.calls, <_LoggedMethodCall>[ - const _LoggedMethodCall( - 'pickMultiImage', - arguments: { - 'maxWidth': null, - 'maxHeight': null, - 'imageQuality': null, - 'requestFullMetadata': true, - 'limit': null, - }, - ), - const _LoggedMethodCall( - 'pickMultiImage', - arguments: { - 'maxWidth': 10.0, - 'maxHeight': null, - 'imageQuality': null, - 'requestFullMetadata': true, - 'limit': null, - }, - ), - const _LoggedMethodCall( - 'pickMultiImage', - arguments: { - 'maxWidth': null, - 'maxHeight': 10.0, - 'imageQuality': null, - 'requestFullMetadata': true, - 'limit': null, - }, - ), - const _LoggedMethodCall( - 'pickMultiImage', - arguments: { - 'maxWidth': 10.0, - 'maxHeight': 20.0, - 'imageQuality': null, - 'requestFullMetadata': true, - 'limit': null, - }, - ), - const _LoggedMethodCall( - 'pickMultiImage', - arguments: { - 'maxWidth': 10.0, - 'maxHeight': null, - 'imageQuality': 70, - 'requestFullMetadata': true, - 'limit': null, - }, - ), - const _LoggedMethodCall( - 'pickMultiImage', - arguments: { - 'maxWidth': null, - 'maxHeight': 10.0, - 'imageQuality': 70, - 'requestFullMetadata': true, - 'limit': null, - }, - ), - const _LoggedMethodCall( - 'pickMultiImage', - arguments: { - 'maxWidth': 10.0, - 'maxHeight': 20.0, - 'imageQuality': 70, - 'requestFullMetadata': true, - 'limit': null, - }, - ), - ]); + + expect(api.passedMaxSize?.width, 10); + expect(api.passedMaxSize?.height, 20); }); test('does not accept a negative width or height argument', () { @@ -500,264 +161,102 @@ void main() { }); test('returns null for an empty list', () async { - log.returnValue = []; + api.returnValue = []; expect(await picker.pickMultiImage(), isNull); }); }); group('#pickVideo', () { - test('passes the image source argument correctly', () async { + test('calls the method correctly with default arguments', () async { + api.returnValue = ['/foo.mp4']; + final PickedFile? result = await picker.pickVideo( + source: ImageSource.camera, + ); + + expect(result?.path, '/foo.mp4'); + expect(api.passedSelectionType, _SelectionType.video); + expect(api.passedMaxDurationSeconds, null); + }); + + test('passes the camera source argument correctly', () async { await picker.pickVideo(source: ImageSource.camera); + + expect(api.passedSource?.type, SourceType.camera); + }); + + test('passes the gallery source argument correctly', () async { await picker.pickVideo(source: ImageSource.gallery); - expect(log.calls, <_LoggedMethodCall>[ - const _LoggedMethodCall( - 'pickVideo', - arguments: { - 'source': SourceType.camera, - 'cameraDevice': SourceCamera.rear, - 'maxDuration': null, - }, - ), - const _LoggedMethodCall( - 'pickVideo', - arguments: { - 'source': SourceType.gallery, - 'cameraDevice': SourceCamera.rear, - 'maxDuration': null, - }, - ), - ]); + expect(api.passedSource?.type, SourceType.gallery); }); test('passes the duration argument correctly', () async { - await picker.pickVideo(source: ImageSource.camera); - await picker.pickVideo( - source: ImageSource.camera, - maxDuration: const Duration(seconds: 10), - ); await picker.pickVideo( source: ImageSource.camera, maxDuration: const Duration(minutes: 1), ); - await picker.pickVideo( - source: ImageSource.camera, - maxDuration: const Duration(hours: 1), - ); - expect(log.calls, <_LoggedMethodCall>[ - const _LoggedMethodCall( - 'pickVideo', - arguments: { - 'source': SourceType.camera, - 'maxDuration': null, - 'cameraDevice': SourceCamera.rear, - }, - ), - const _LoggedMethodCall( - 'pickVideo', - arguments: { - 'source': SourceType.camera, - 'maxDuration': 10, - 'cameraDevice': SourceCamera.rear, - }, - ), - const _LoggedMethodCall( - 'pickVideo', - arguments: { - 'source': SourceType.camera, - 'maxDuration': 60, - 'cameraDevice': SourceCamera.rear, - }, - ), - const _LoggedMethodCall( - 'pickVideo', - arguments: { - 'source': SourceType.camera, - 'maxDuration': 3600, - 'cameraDevice': SourceCamera.rear, - }, - ), - ]); + + expect(api.passedMaxDurationSeconds, 60); }); test('handles a null video path response gracefully', () async { - log.returnValue = null; + api.returnValue = []; expect(await picker.pickVideo(source: ImageSource.gallery), isNull); expect(await picker.pickVideo(source: ImageSource.camera), isNull); }); - test('camera position defaults to back', () async { - await picker.pickVideo(source: ImageSource.camera); - - expect(log.calls, <_LoggedMethodCall>[ - const _LoggedMethodCall( - 'pickVideo', - arguments: { - 'source': SourceType.camera, - 'cameraDevice': SourceCamera.rear, - 'maxDuration': null, - }, - ), - ]); - }); - test('camera position can set to front', () async { await picker.pickVideo( source: ImageSource.camera, preferredCameraDevice: CameraDevice.front, ); - expect(log.calls, <_LoggedMethodCall>[ - const _LoggedMethodCall( - 'pickVideo', - arguments: { - 'source': SourceType.camera, - 'maxDuration': null, - 'cameraDevice': SourceCamera.front, - }, - ), - ]); + expect(api.passedSource?.camera, SourceCamera.front); }); }); group('#getImage', () { - test('passes the image source argument correctly', () async { + test('calls the method correctly with default arguments', () async { + api.returnValue = ['/foo.png']; + final XFile? result = await picker.getImage(source: ImageSource.camera); + + expect(result?.path, '/foo.png'); + expect(api.passedSelectionType, _SelectionType.image); + expect(api.passedRequestFullMetadata, true); + expect(api.passedMaxSize?.width, null); + expect(api.passedMaxSize?.height, null); + expect(api.passedImageQuality, null); + }); + + test('passes the camera image source argument correctly', () async { await picker.getImage(source: ImageSource.camera); + + expect(api.passedSource?.type, SourceType.camera); + }); + + test('passes the gallery image source argument correctly', () async { await picker.getImage(source: ImageSource.gallery); - expect(log.calls, <_LoggedMethodCall>[ - const _LoggedMethodCall( - 'pickImage', - arguments: { - 'source': SourceType.camera, - 'maxWidth': null, - 'maxHeight': null, - 'imageQuality': null, - 'cameraDevice': SourceCamera.rear, - 'requestFullMetadata': true, - }, - ), - const _LoggedMethodCall( - 'pickImage', - arguments: { - 'source': SourceType.gallery, - 'maxWidth': null, - 'maxHeight': null, - 'imageQuality': null, - 'cameraDevice': SourceCamera.rear, - 'requestFullMetadata': true, - }, - ), - ]); + expect(api.passedSource?.type, SourceType.gallery); }); test('passes the width and height arguments correctly', () async { - await picker.getImage(source: ImageSource.camera); - await picker.getImage(source: ImageSource.camera, maxWidth: 10.0); - await picker.getImage(source: ImageSource.camera, maxHeight: 10.0); await picker.getImage( source: ImageSource.camera, maxWidth: 10.0, maxHeight: 20.0, ); - await picker.getImage( - source: ImageSource.camera, - maxWidth: 10.0, - imageQuality: 70, - ); - await picker.getImage( - source: ImageSource.camera, - maxHeight: 10.0, - imageQuality: 70, - ); - await picker.getImage( - source: ImageSource.camera, - maxWidth: 10.0, - maxHeight: 20.0, - imageQuality: 70, - ); - - expect(log.calls, <_LoggedMethodCall>[ - const _LoggedMethodCall( - 'pickImage', - arguments: { - 'source': SourceType.camera, - 'maxWidth': null, - 'maxHeight': null, - 'imageQuality': null, - 'cameraDevice': SourceCamera.rear, - 'requestFullMetadata': true, - }, - ), - const _LoggedMethodCall( - 'pickImage', - arguments: { - 'source': SourceType.camera, - 'maxWidth': 10.0, - 'maxHeight': null, - 'imageQuality': null, - 'cameraDevice': SourceCamera.rear, - 'requestFullMetadata': true, - }, - ), - const _LoggedMethodCall( - 'pickImage', - arguments: { - 'source': SourceType.camera, - 'maxWidth': null, - 'maxHeight': 10.0, - 'imageQuality': null, - 'cameraDevice': SourceCamera.rear, - 'requestFullMetadata': true, - }, - ), - const _LoggedMethodCall( - 'pickImage', - arguments: { - 'source': SourceType.camera, - 'maxWidth': 10.0, - 'maxHeight': 20.0, - 'imageQuality': null, - 'cameraDevice': SourceCamera.rear, - 'requestFullMetadata': true, - }, - ), - const _LoggedMethodCall( - 'pickImage', - arguments: { - 'source': SourceType.camera, - 'maxWidth': 10.0, - 'maxHeight': null, - 'imageQuality': 70, - 'cameraDevice': SourceCamera.rear, - 'requestFullMetadata': true, - }, - ), - const _LoggedMethodCall( - 'pickImage', - arguments: { - 'source': SourceType.camera, - 'maxWidth': null, - 'maxHeight': 10.0, - 'imageQuality': 70, - 'cameraDevice': SourceCamera.rear, - 'requestFullMetadata': true, - }, - ), - const _LoggedMethodCall( - 'pickImage', - arguments: { - 'source': SourceType.camera, - 'maxWidth': 10.0, - 'maxHeight': 20.0, - 'imageQuality': 70, - 'cameraDevice': SourceCamera.rear, - 'requestFullMetadata': true, - }, - ), - ]); + + expect(api.passedMaxSize?.width, 10); + expect(api.passedMaxSize?.height, 20); + }); + + test('passes image quality argument correctly', () async { + await picker.getImage(source: ImageSource.camera, imageQuality: 70); + + expect(api.passedImageQuality, 70); }); test('does not accept an invalid imageQuality argument', () { @@ -795,7 +294,7 @@ void main() { }); test('handles a null image path response gracefully', () async { - log.returnValue = null; + api.returnValue = []; expect(await picker.getImage(source: ImageSource.gallery), isNull); expect(await picker.getImage(source: ImageSource.camera), isNull); @@ -804,19 +303,7 @@ void main() { test('camera position defaults to back', () async { await picker.getImage(source: ImageSource.camera); - expect(log.calls, <_LoggedMethodCall>[ - const _LoggedMethodCall( - 'pickImage', - arguments: { - 'source': SourceType.camera, - 'maxWidth': null, - 'maxHeight': null, - 'imageQuality': null, - 'cameraDevice': SourceCamera.rear, - 'requestFullMetadata': true, - }, - ), - ]); + expect(api.passedSource?.camera, SourceCamera.rear); }); test('camera position can set to front', () async { @@ -825,138 +312,46 @@ void main() { preferredCameraDevice: CameraDevice.front, ); - expect(log.calls, <_LoggedMethodCall>[ - const _LoggedMethodCall( - 'pickImage', - arguments: { - 'source': SourceType.camera, - 'maxWidth': null, - 'maxHeight': null, - 'imageQuality': null, - 'cameraDevice': SourceCamera.front, - 'requestFullMetadata': true, - }, - ), - ]); + expect(api.passedSource?.camera, SourceCamera.front); }); }); group('#getMultiImage', () { - test('calls the method correctly', () async { - log.returnValue = ['0', '1']; - await picker.getMultiImage(); - - expect(log.calls, <_LoggedMethodCall>[ - const _LoggedMethodCall( - 'pickMultiImage', - arguments: { - 'maxWidth': null, - 'maxHeight': null, - 'imageQuality': null, - 'requestFullMetadata': true, - 'limit': null, - }, - ), - ]); + test('calls the method correctly with default arguments', () async { + api.returnValue = ['/foo.png', '/bar.png']; + final List? result = await picker.getMultiImage(); + + expect(result?.length, 2); + expect(result?[0].path, '/foo.png'); + expect(result?[1].path, '/bar.png'); + expect(api.passedSelectionType, _SelectionType.multiImage); + expect(api.passedRequestFullMetadata, true); + expect(api.passedMaxSize?.width, null); + expect(api.passedMaxSize?.height, null); + expect(api.passedImageQuality, null); + expect(api.passedLimit, null); }); test('passes the width and height arguments correctly', () async { - log.returnValue = ['0', '1']; - await picker.getMultiImage(); - await picker.getMultiImage(maxWidth: 10.0); - await picker.getMultiImage(maxHeight: 10.0); await picker.getMultiImage(maxWidth: 10.0, maxHeight: 20.0); - await picker.getMultiImage(maxWidth: 10.0, imageQuality: 70); - await picker.getMultiImage(maxHeight: 10.0, imageQuality: 70); - await picker.getMultiImage( - maxWidth: 10.0, - maxHeight: 20.0, - imageQuality: 70, - ); - - expect(log.calls, <_LoggedMethodCall>[ - const _LoggedMethodCall( - 'pickMultiImage', - arguments: { - 'maxWidth': null, - 'maxHeight': null, - 'imageQuality': null, - 'requestFullMetadata': true, - 'limit': null, - }, - ), - const _LoggedMethodCall( - 'pickMultiImage', - arguments: { - 'maxWidth': 10.0, - 'maxHeight': null, - 'imageQuality': null, - 'requestFullMetadata': true, - 'limit': null, - }, - ), - const _LoggedMethodCall( - 'pickMultiImage', - arguments: { - 'maxWidth': null, - 'maxHeight': 10.0, - 'imageQuality': null, - 'requestFullMetadata': true, - 'limit': null, - }, - ), - const _LoggedMethodCall( - 'pickMultiImage', - arguments: { - 'maxWidth': 10.0, - 'maxHeight': 20.0, - 'imageQuality': null, - 'requestFullMetadata': true, - 'limit': null, - }, - ), - const _LoggedMethodCall( - 'pickMultiImage', - arguments: { - 'maxWidth': 10.0, - 'maxHeight': null, - 'imageQuality': 70, - 'requestFullMetadata': true, - 'limit': null, - }, - ), - const _LoggedMethodCall( - 'pickMultiImage', - arguments: { - 'maxWidth': null, - 'maxHeight': 10.0, - 'imageQuality': 70, - 'requestFullMetadata': true, - 'limit': null, - }, - ), - const _LoggedMethodCall( - 'pickMultiImage', - arguments: { - 'maxWidth': 10.0, - 'maxHeight': 20.0, - 'imageQuality': 70, - 'requestFullMetadata': true, - 'limit': null, - }, - ), - ]); + + expect(api.passedMaxSize?.width, 10); + expect(api.passedMaxSize?.height, 20); + }); + + test('passes the image quality argument correctly', () async { + await picker.getMultiImage(imageQuality: 70); + + expect(api.passedImageQuality, 70); }); test('does not accept a negative width or height argument', () { - log.returnValue = ['0', '1']; expect(() => picker.getMultiImage(maxWidth: -1.0), throwsArgumentError); expect(() => picker.getMultiImage(maxHeight: -1.0), throwsArgumentError); }); test('does not accept an invalid imageQuality argument', () { - log.returnValue = ['0', '1']; expect(() => picker.getMultiImage(imageQuality: -1), throwsArgumentError); expect( @@ -966,47 +361,32 @@ void main() { }); test('returns null for an empty list', () async { - log.returnValue = []; + api.returnValue = []; expect(await picker.getMultiImage(), isNull); }); }); group('#getMedia', () { - test('calls the method correctly', () async { - log.returnValue = ['0', '1']; - await picker.getMedia(options: const MediaOptions(allowMultiple: true)); - - expect(log.calls, <_LoggedMethodCall>[ - const _LoggedMethodCall( - 'pickMedia', - arguments: { - 'maxWidth': null, - 'maxHeight': null, - 'imageQuality': null, - 'requestFullMetadata': true, - 'allowMultiple': true, - 'limit': null, - }, - ), - ]); + test('calls the method correctly with default arguments', () async { + api.returnValue = ['/foo.png', '/bar.mp4']; + final List result = await picker.getMedia( + options: const MediaOptions(allowMultiple: true), + ); + + expect(result.length, 2); + expect(result[0].path, '/foo.png'); + expect(result[1].path, '/bar.mp4'); + expect(api.passedSelectionType, _SelectionType.media); + expect(api.passedMediaSelectionOptions?.allowMultiple, true); + expect(api.passedMediaSelectionOptions?.requestFullMetadata, true); + expect(api.passedMediaSelectionOptions?.maxSize.width, null); + expect(api.passedMediaSelectionOptions?.maxSize.height, null); + expect(api.passedMediaSelectionOptions?.imageQuality, null); + expect(api.passedMediaSelectionOptions?.limit, null); }); test('passes the width and height arguments correctly', () async { - log.returnValue = ['0', '1']; - await picker.getMedia(options: const MediaOptions(allowMultiple: true)); - await picker.getMedia( - options: MediaOptions( - allowMultiple: true, - imageOptions: ImageOptions.createAndValidate(maxWidth: 10.0), - ), - ); - await picker.getMedia( - options: MediaOptions( - allowMultiple: true, - imageOptions: ImageOptions.createAndValidate(maxHeight: 10.0), - ), - ); await picker.getMedia( options: MediaOptions( allowMultiple: true, @@ -1016,140 +396,23 @@ void main() { ), ), ); + + expect(api.passedMediaSelectionOptions?.maxSize.width, 10); + expect(api.passedMediaSelectionOptions?.maxSize.height, 20); + }); + + test('passes the image quality argument correctly', () async { await picker.getMedia( options: MediaOptions( allowMultiple: true, - imageOptions: ImageOptions.createAndValidate( - maxWidth: 10.0, - imageQuality: 70, - ), - ), - ); - await picker.getMedia( - options: MediaOptions( - allowMultiple: true, - imageOptions: ImageOptions.createAndValidate( - maxHeight: 10.0, - imageQuality: 70, - ), - ), - ); - await picker.getMedia( - options: MediaOptions( - allowMultiple: true, - imageOptions: ImageOptions.createAndValidate( - maxWidth: 10.0, - maxHeight: 20.0, - imageQuality: 70, - ), - ), - ); - await picker.getMedia( - options: MediaOptions( - allowMultiple: true, - imageOptions: ImageOptions.createAndValidate( - maxWidth: 10.0, - maxHeight: 20.0, - imageQuality: 70, - ), - limit: 5, + imageOptions: ImageOptions.createAndValidate(imageQuality: 70), ), ); - expect(log.calls, <_LoggedMethodCall>[ - const _LoggedMethodCall( - 'pickMedia', - arguments: { - 'maxWidth': null, - 'maxHeight': null, - 'imageQuality': null, - 'requestFullMetadata': true, - 'allowMultiple': true, - 'limit': null, - }, - ), - const _LoggedMethodCall( - 'pickMedia', - arguments: { - 'maxWidth': 10.0, - 'maxHeight': null, - 'imageQuality': null, - 'requestFullMetadata': true, - 'allowMultiple': true, - 'limit': null, - }, - ), - const _LoggedMethodCall( - 'pickMedia', - arguments: { - 'maxWidth': null, - 'maxHeight': 10.0, - 'imageQuality': null, - 'requestFullMetadata': true, - 'allowMultiple': true, - 'limit': null, - }, - ), - const _LoggedMethodCall( - 'pickMedia', - arguments: { - 'maxWidth': 10.0, - 'maxHeight': 20.0, - 'imageQuality': null, - 'requestFullMetadata': true, - 'allowMultiple': true, - 'limit': null, - }, - ), - const _LoggedMethodCall( - 'pickMedia', - arguments: { - 'maxWidth': 10.0, - 'maxHeight': null, - 'imageQuality': 70, - 'requestFullMetadata': true, - 'allowMultiple': true, - 'limit': null, - }, - ), - const _LoggedMethodCall( - 'pickMedia', - arguments: { - 'maxWidth': null, - 'maxHeight': 10.0, - 'imageQuality': 70, - 'requestFullMetadata': true, - 'allowMultiple': true, - 'limit': null, - }, - ), - const _LoggedMethodCall( - 'pickMedia', - arguments: { - 'maxWidth': 10.0, - 'maxHeight': 20.0, - 'imageQuality': 70, - 'requestFullMetadata': true, - 'allowMultiple': true, - 'limit': null, - }, - ), - const _LoggedMethodCall( - 'pickMedia', - arguments: { - 'maxWidth': 10.0, - 'maxHeight': 20.0, - 'imageQuality': 70, - 'requestFullMetadata': true, - 'allowMultiple': true, - 'limit': 5, - }, - ), - ]); + expect(api.passedMediaSelectionOptions?.imageQuality, 70); }); test('passes request metadata argument correctly', () async { - log.returnValue = ['0', '1']; await picker.getMedia( options: const MediaOptions( allowMultiple: true, @@ -1157,42 +420,16 @@ void main() { ), ); - expect(log.calls, <_LoggedMethodCall>[ - const _LoggedMethodCall( - 'pickMedia', - arguments: { - 'maxWidth': null, - 'maxHeight': null, - 'imageQuality': null, - 'requestFullMetadata': false, - 'allowMultiple': true, - 'limit': null, - }, - ), - ]); + expect(api.passedMediaSelectionOptions?.requestFullMetadata, false); }); test('passes allowMultiple argument correctly', () async { - log.returnValue = ['0', '1']; await picker.getMedia(options: const MediaOptions(allowMultiple: false)); - expect(log.calls, <_LoggedMethodCall>[ - const _LoggedMethodCall( - 'pickMedia', - arguments: { - 'maxWidth': null, - 'maxHeight': null, - 'imageQuality': null, - 'requestFullMetadata': true, - 'allowMultiple': false, - 'limit': null, - }, - ), - ]); + expect(api.passedMediaSelectionOptions?.allowMultiple, false); }); test('does not accept a negative width or height argument', () { - log.returnValue = ['0', '1']; expect( () => picker.getMedia( options: MediaOptions( @@ -1215,7 +452,6 @@ void main() { }); test('does not accept an invalid imageQuality argument', () { - log.returnValue = ['0', '1']; expect( () => picker.getMedia( options: MediaOptions( @@ -1238,7 +474,6 @@ void main() { }); test('does not accept an invalid limit argument', () { - log.returnValue = ['0', '1']; final Matcher throwsLimitArgumentError = throwsA( isA() .having((ArgumentError error) => error.name, 'name', 'limit') @@ -1281,7 +516,7 @@ void main() { }); test('handles a empty path response gracefully', () async { - log.returnValue = []; + api.returnValue = []; expect( await picker.getMedia(options: const MediaOptions(allowMultiple: true)), @@ -1291,82 +526,38 @@ void main() { }); group('#getVideo', () { - test('passes the image source argument correctly', () async { + test('calls the method correctly with default arguments', () async { + api.returnValue = ['/foo.mp4']; + final XFile? result = await picker.getVideo(source: ImageSource.gallery); + + expect(result?.path, '/foo.mp4'); + expect(api.passedSelectionType, _SelectionType.video); + expect(api.passedMaxDurationSeconds, null); + }); + + test('passes the camera image source argument correctly', () async { await picker.getVideo(source: ImageSource.camera); + + expect(api.passedSource?.type, SourceType.camera); + }); + + test('passes the gallery image source argument correctly', () async { await picker.getVideo(source: ImageSource.gallery); - expect(log.calls, <_LoggedMethodCall>[ - const _LoggedMethodCall( - 'pickVideo', - arguments: { - 'source': SourceType.camera, - 'cameraDevice': SourceCamera.rear, - 'maxDuration': null, - }, - ), - const _LoggedMethodCall( - 'pickVideo', - arguments: { - 'source': SourceType.gallery, - 'cameraDevice': SourceCamera.rear, - 'maxDuration': null, - }, - ), - ]); + expect(api.passedSource?.type, SourceType.gallery); }); test('passes the duration argument correctly', () async { - await picker.getVideo(source: ImageSource.camera); - await picker.getVideo( - source: ImageSource.camera, - maxDuration: const Duration(seconds: 10), - ); await picker.getVideo( source: ImageSource.camera, maxDuration: const Duration(minutes: 1), ); - await picker.getVideo( - source: ImageSource.camera, - maxDuration: const Duration(hours: 1), - ); - expect(log.calls, <_LoggedMethodCall>[ - const _LoggedMethodCall( - 'pickVideo', - arguments: { - 'source': SourceType.camera, - 'maxDuration': null, - 'cameraDevice': SourceCamera.rear, - }, - ), - const _LoggedMethodCall( - 'pickVideo', - arguments: { - 'source': SourceType.camera, - 'maxDuration': 10, - 'cameraDevice': SourceCamera.rear, - }, - ), - const _LoggedMethodCall( - 'pickVideo', - arguments: { - 'source': SourceType.camera, - 'maxDuration': 60, - 'cameraDevice': SourceCamera.rear, - }, - ), - const _LoggedMethodCall( - 'pickVideo', - arguments: { - 'source': SourceType.camera, - 'maxDuration': 3600, - 'cameraDevice': SourceCamera.rear, - }, - ), - ]); + + expect(api.passedMaxDurationSeconds, 60); }); test('handles a null video path response gracefully', () async { - log.returnValue = null; + api.returnValue = []; expect(await picker.getVideo(source: ImageSource.gallery), isNull); expect(await picker.getVideo(source: ImageSource.camera), isNull); @@ -1375,16 +566,7 @@ void main() { test('camera position defaults to back', () async { await picker.getVideo(source: ImageSource.camera); - expect(log.calls, <_LoggedMethodCall>[ - const _LoggedMethodCall( - 'pickVideo', - arguments: { - 'source': SourceType.camera, - 'cameraDevice': SourceCamera.rear, - 'maxDuration': null, - }, - ), - ]); + expect(api.passedSource?.camera, SourceCamera.rear); }); test('camera position can set to front', () async { @@ -1393,34 +575,25 @@ void main() { preferredCameraDevice: CameraDevice.front, ); - expect(log.calls, <_LoggedMethodCall>[ - const _LoggedMethodCall( - 'pickVideo', - arguments: { - 'source': SourceType.camera, - 'maxDuration': null, - 'cameraDevice': SourceCamera.front, - }, - ), - ]); + expect(api.passedSource?.camera, SourceCamera.front); }); }); group('#getMultiVideoWithOptions', () { test('calls the method correctly', () async { - log.returnValue = ['/foo.mp4', 'bar.mp4']; - await picker.getMultiVideoWithOptions(); + api.returnValue = ['/foo.mp4', 'bar.mp4']; + final List result = await picker.getMultiVideoWithOptions(); - expect(log.calls, <_LoggedMethodCall>[ - const _LoggedMethodCall( - 'pickMultiVideo', - arguments: {'maxDuration': null, 'limit': null}, - ), - ]); + expect(result.length, 2); + expect(result[0].path, '/foo.mp4'); + expect(result[1].path, 'bar.mp4'); + expect(api.passedSelectionType, _SelectionType.multiVideo); + expect(api.passedMaxDurationSeconds, null); + expect(api.passedLimit, null); }); test('passes the arguments correctly', () async { - log.returnValue = []; + api.returnValue = []; await picker.getMultiVideoWithOptions( options: const MultiVideoPickerOptions( maxDuration: Duration(seconds: 10), @@ -1428,156 +601,55 @@ void main() { ), ); - expect(log.calls, <_LoggedMethodCall>[ - const _LoggedMethodCall( - 'pickMultiVideo', - arguments: {'maxDuration': 10, 'limit': 5}, - ), - ]); + expect(api.passedMaxDurationSeconds, 10); + expect(api.passedLimit, 5); }); }); group('#getImageFromSource', () { - test('passes the image source argument correctly', () async { + test('calls the method correctly with default arguments', () async { + api.returnValue = ['/foo.png']; + final XFile? result = await picker.getImageFromSource( + source: ImageSource.camera, + ); + + expect(result?.path, '/foo.png'); + expect(api.passedSelectionType, _SelectionType.image); + expect(api.passedRequestFullMetadata, true); + expect(api.passedMaxSize?.width, null); + expect(api.passedMaxSize?.height, null); + expect(api.passedImageQuality, null); + }); + + test('passes the camera image source argument correctly', () async { await picker.getImageFromSource(source: ImageSource.camera); + + expect(api.passedSource?.type, SourceType.camera); + }); + + test('passes the gallery image source argument correctly', () async { await picker.getImageFromSource(source: ImageSource.gallery); - expect(log.calls, <_LoggedMethodCall>[ - const _LoggedMethodCall( - 'pickImage', - arguments: { - 'source': SourceType.camera, - 'maxWidth': null, - 'maxHeight': null, - 'imageQuality': null, - 'cameraDevice': SourceCamera.rear, - 'requestFullMetadata': true, - }, - ), - const _LoggedMethodCall( - 'pickImage', - arguments: { - 'source': SourceType.gallery, - 'maxWidth': null, - 'maxHeight': null, - 'imageQuality': null, - 'cameraDevice': SourceCamera.rear, - 'requestFullMetadata': true, - }, - ), - ]); + expect(api.passedSource?.type, SourceType.gallery); }); test('passes the width and height arguments correctly', () async { - await picker.getImageFromSource(source: ImageSource.camera); - await picker.getImageFromSource( - source: ImageSource.camera, - options: const ImagePickerOptions(maxWidth: 10.0), - ); - await picker.getImageFromSource( - source: ImageSource.camera, - options: const ImagePickerOptions(maxHeight: 10.0), - ); await picker.getImageFromSource( source: ImageSource.camera, options: const ImagePickerOptions(maxWidth: 10.0, maxHeight: 20.0), ); + + expect(api.passedMaxSize?.width, 10); + expect(api.passedMaxSize?.height, 20); + }); + + test('passes the image quality argument correctly', () async { await picker.getImageFromSource( source: ImageSource.camera, - options: const ImagePickerOptions(maxWidth: 10.0, imageQuality: 70), - ); - await picker.getImageFromSource( - source: ImageSource.camera, - options: const ImagePickerOptions(maxHeight: 10.0, imageQuality: 70), - ); - await picker.getImageFromSource( - source: ImageSource.camera, - options: const ImagePickerOptions( - maxWidth: 10.0, - maxHeight: 20.0, - imageQuality: 70, - ), + options: const ImagePickerOptions(imageQuality: 70), ); - expect(log.calls, <_LoggedMethodCall>[ - const _LoggedMethodCall( - 'pickImage', - arguments: { - 'source': SourceType.camera, - 'maxWidth': null, - 'maxHeight': null, - 'imageQuality': null, - 'cameraDevice': SourceCamera.rear, - 'requestFullMetadata': true, - }, - ), - const _LoggedMethodCall( - 'pickImage', - arguments: { - 'source': SourceType.camera, - 'maxWidth': 10.0, - 'maxHeight': null, - 'imageQuality': null, - 'cameraDevice': SourceCamera.rear, - 'requestFullMetadata': true, - }, - ), - const _LoggedMethodCall( - 'pickImage', - arguments: { - 'source': SourceType.camera, - 'maxWidth': null, - 'maxHeight': 10.0, - 'imageQuality': null, - 'cameraDevice': SourceCamera.rear, - 'requestFullMetadata': true, - }, - ), - const _LoggedMethodCall( - 'pickImage', - arguments: { - 'source': SourceType.camera, - 'maxWidth': 10.0, - 'maxHeight': 20.0, - 'imageQuality': null, - 'cameraDevice': SourceCamera.rear, - 'requestFullMetadata': true, - }, - ), - const _LoggedMethodCall( - 'pickImage', - arguments: { - 'source': SourceType.camera, - 'maxWidth': 10.0, - 'maxHeight': null, - 'imageQuality': 70, - 'cameraDevice': SourceCamera.rear, - 'requestFullMetadata': true, - }, - ), - const _LoggedMethodCall( - 'pickImage', - arguments: { - 'source': SourceType.camera, - 'maxWidth': null, - 'maxHeight': 10.0, - 'imageQuality': 70, - 'cameraDevice': SourceCamera.rear, - 'requestFullMetadata': true, - }, - ), - const _LoggedMethodCall( - 'pickImage', - arguments: { - 'source': SourceType.camera, - 'maxWidth': 10.0, - 'maxHeight': 20.0, - 'imageQuality': 70, - 'cameraDevice': SourceCamera.rear, - 'requestFullMetadata': true, - }, - ), - ]); + expect(api.passedImageQuality, 70); }); test('does not accept an invalid imageQuality argument', () { @@ -1633,7 +705,7 @@ void main() { }); test('handles a null image path response gracefully', () async { - log.returnValue = null; + api.returnValue = []; expect( await picker.getImageFromSource(source: ImageSource.gallery), @@ -1648,19 +720,7 @@ void main() { test('camera position defaults to back', () async { await picker.getImageFromSource(source: ImageSource.camera); - expect(log.calls, <_LoggedMethodCall>[ - const _LoggedMethodCall( - 'pickImage', - arguments: { - 'source': SourceType.camera, - 'maxWidth': null, - 'maxHeight': null, - 'imageQuality': null, - 'cameraDevice': SourceCamera.rear, - 'requestFullMetadata': true, - }, - ), - ]); + expect(api.passedSource?.camera, SourceCamera.rear); }); test('camera position can set to front', () async { @@ -1671,37 +731,7 @@ void main() { ), ); - expect(log.calls, <_LoggedMethodCall>[ - const _LoggedMethodCall( - 'pickImage', - arguments: { - 'source': SourceType.camera, - 'maxWidth': null, - 'maxHeight': null, - 'imageQuality': null, - 'cameraDevice': SourceCamera.front, - 'requestFullMetadata': true, - }, - ), - ]); - }); - - test('Request full metadata argument defaults to true', () async { - await picker.getImageFromSource(source: ImageSource.gallery); - - expect(log.calls, <_LoggedMethodCall>[ - const _LoggedMethodCall( - 'pickImage', - arguments: { - 'source': SourceType.gallery, - 'maxWidth': null, - 'maxHeight': null, - 'imageQuality': null, - 'cameraDevice': SourceCamera.rear, - 'requestFullMetadata': true, - }, - ), - ]); + expect(api.passedSource?.camera, SourceCamera.front); }); test('passes the request full metadata argument correctly', () async { @@ -1710,175 +740,56 @@ void main() { options: const ImagePickerOptions(requestFullMetadata: false), ); - expect(log.calls, <_LoggedMethodCall>[ - const _LoggedMethodCall( - 'pickImage', - arguments: { - 'source': SourceType.gallery, - 'maxWidth': null, - 'maxHeight': null, - 'imageQuality': null, - 'cameraDevice': SourceCamera.rear, - 'requestFullMetadata': false, - }, - ), - ]); + expect(api.passedRequestFullMetadata, false); }); }); group('#getMultiImageWithOptions', () { - test('calls the method correctly', () async { - log.returnValue = ['0', '1']; - await picker.getMultiImageWithOptions(); - - expect(log.calls, <_LoggedMethodCall>[ - const _LoggedMethodCall( - 'pickMultiImage', - arguments: { - 'maxWidth': null, - 'maxHeight': null, - 'imageQuality': null, - 'requestFullMetadata': true, - 'limit': null, - }, - ), - ]); + test('calls the method correctly with default arguments', () async { + api.returnValue = ['/foo.png', '/bar.png']; + final List result = await picker.getMultiImageWithOptions(); + + expect(result.length, 2); + expect(result[0].path, '/foo.png'); + expect(result[1].path, '/bar.png'); + expect(api.passedSelectionType, _SelectionType.multiImage); + expect(api.passedRequestFullMetadata, true); + expect(api.passedMaxSize?.width, null); + expect(api.passedMaxSize?.height, null); + expect(api.passedImageQuality, null); + expect(api.passedLimit, null); }); test('passes the width and height arguments correctly', () async { - log.returnValue = ['0', '1']; - await picker.getMultiImageWithOptions(); - await picker.getMultiImageWithOptions( - options: const MultiImagePickerOptions( - imageOptions: ImageOptions(maxWidth: 10.0), - ), - ); - await picker.getMultiImageWithOptions( - options: const MultiImagePickerOptions( - imageOptions: ImageOptions(maxHeight: 10.0), - ), - ); await picker.getMultiImageWithOptions( options: const MultiImagePickerOptions( imageOptions: ImageOptions(maxWidth: 10.0, maxHeight: 20.0), ), ); + + expect(api.passedMaxSize?.width, 10); + expect(api.passedMaxSize?.height, 20); + }); + + test('passes the image quality argument correctly', () async { await picker.getMultiImageWithOptions( options: const MultiImagePickerOptions( - imageOptions: ImageOptions(maxWidth: 10.0, imageQuality: 70), - ), - ); - await picker.getMultiImageWithOptions( - options: const MultiImagePickerOptions( - imageOptions: ImageOptions(maxHeight: 10.0, imageQuality: 70), - ), - ); - await picker.getMultiImageWithOptions( - options: const MultiImagePickerOptions( - imageOptions: ImageOptions( - maxWidth: 10.0, - maxHeight: 20.0, - imageQuality: 70, - ), + imageOptions: ImageOptions(imageQuality: 70), ), ); + + expect(api.passedImageQuality, 70); + }); + + test('passes the limit argument correctly', () async { await picker.getMultiImageWithOptions( - options: const MultiImagePickerOptions( - imageOptions: ImageOptions( - maxWidth: 10.0, - maxHeight: 20.0, - imageQuality: 70, - ), - limit: 5, - ), + options: const MultiImagePickerOptions(limit: 5), ); - expect(log.calls, <_LoggedMethodCall>[ - const _LoggedMethodCall( - 'pickMultiImage', - arguments: { - 'maxWidth': null, - 'maxHeight': null, - 'imageQuality': null, - 'requestFullMetadata': true, - 'limit': null, - }, - ), - const _LoggedMethodCall( - 'pickMultiImage', - arguments: { - 'maxWidth': 10.0, - 'maxHeight': null, - 'imageQuality': null, - 'requestFullMetadata': true, - 'limit': null, - }, - ), - const _LoggedMethodCall( - 'pickMultiImage', - arguments: { - 'maxWidth': null, - 'maxHeight': 10.0, - 'imageQuality': null, - 'requestFullMetadata': true, - 'limit': null, - }, - ), - const _LoggedMethodCall( - 'pickMultiImage', - arguments: { - 'maxWidth': 10.0, - 'maxHeight': 20.0, - 'imageQuality': null, - 'requestFullMetadata': true, - 'limit': null, - }, - ), - const _LoggedMethodCall( - 'pickMultiImage', - arguments: { - 'maxWidth': 10.0, - 'maxHeight': null, - 'imageQuality': 70, - 'requestFullMetadata': true, - 'limit': null, - }, - ), - const _LoggedMethodCall( - 'pickMultiImage', - arguments: { - 'maxWidth': null, - 'maxHeight': 10.0, - 'imageQuality': 70, - 'requestFullMetadata': true, - 'limit': null, - }, - ), - const _LoggedMethodCall( - 'pickMultiImage', - arguments: { - 'maxWidth': 10.0, - 'maxHeight': 20.0, - 'imageQuality': 70, - 'requestFullMetadata': true, - 'limit': null, - }, - ), - const _LoggedMethodCall( - 'pickMultiImage', - arguments: { - 'maxWidth': 10.0, - 'maxHeight': 20.0, - 'imageQuality': 70, - 'requestFullMetadata': true, - 'limit': 5, - }, - ), - ]); + expect(api.passedLimit, 5); }); test('does not accept a negative width or height argument', () { - log.returnValue = ['0', '1']; expect( () => picker.getMultiImageWithOptions( options: const MultiImagePickerOptions( @@ -1899,7 +810,6 @@ void main() { }); test('does not accept an invalid imageQuality argument', () { - log.returnValue = ['0', '1']; expect( () => picker.getMultiImageWithOptions( options: const MultiImagePickerOptions( @@ -1920,7 +830,6 @@ void main() { }); test('does not accept an invalid limit argument', () { - log.returnValue = ['0', '1']; final Matcher throwsLimitArgumentError = throwsA( isA() .having((ArgumentError error) => error.name, 'name', 'limit') @@ -1954,49 +863,106 @@ void main() { }); test('handles an empty response', () async { - log.returnValue = []; + api.returnValue = []; expect(await picker.getMultiImageWithOptions(), isEmpty); }); - test('Request full metadata argument defaults to true', () async { - log.returnValue = ['0', '1']; - await picker.getMultiImageWithOptions(); - - expect(log.calls, <_LoggedMethodCall>[ - const _LoggedMethodCall( - 'pickMultiImage', - arguments: { - 'maxWidth': null, - 'maxHeight': null, - 'imageQuality': null, - 'requestFullMetadata': true, - 'limit': null, - }, - ), - ]); - }); - test('Passes the request full metadata argument correctly', () async { - log.returnValue = ['0', '1']; await picker.getMultiImageWithOptions( options: const MultiImagePickerOptions( imageOptions: ImageOptions(requestFullMetadata: false), ), ); - expect(log.calls, <_LoggedMethodCall>[ - const _LoggedMethodCall( - 'pickMultiImage', - arguments: { - 'maxWidth': null, - 'maxHeight': null, - 'imageQuality': null, - 'requestFullMetadata': false, - 'limit': null, - }, - ), - ]); + expect(api.passedRequestFullMetadata, false); }); }); } + +enum _SelectionType { image, multiImage, media, video, multiVideo } + +class _FakeImagePickerApi implements ImagePickerApi { + // The value to return from calls. + List returnValue = []; + + _SelectionType? passedSelectionType; + + // Passed arguments. + SourceSpecification? passedSource; + MaxSize? passedMaxSize; + int? passedImageQuality; + bool? passedRequestFullMetadata; + int? passedLimit; + MediaSelectionOptions? passedMediaSelectionOptions; + int? passedMaxDurationSeconds; + + @override + Future pickImage( + SourceSpecification source, + MaxSize maxSize, + int? imageQuality, + bool requestFullMetadata, + ) async { + passedSelectionType = _SelectionType.image; + passedSource = source; + passedMaxSize = maxSize; + passedImageQuality = imageQuality; + passedRequestFullMetadata = requestFullMetadata; + return returnValue.firstOrNull; + } + + @override + Future> pickMultiImage( + MaxSize maxSize, + int? imageQuality, + bool requestFullMetadata, + int? limit, + ) async { + passedSelectionType = _SelectionType.multiImage; + passedMaxSize = maxSize; + passedImageQuality = imageQuality; + passedRequestFullMetadata = requestFullMetadata; + passedLimit = limit; + return returnValue; + } + + @override + Future> pickMedia( + MediaSelectionOptions mediaSelectionOptions, + ) async { + passedSelectionType = _SelectionType.media; + passedMediaSelectionOptions = mediaSelectionOptions; + return returnValue; + } + + @override + Future pickVideo( + SourceSpecification source, + int? maxDurationSeconds, + ) async { + passedSelectionType = _SelectionType.video; + passedSource = source; + passedMaxDurationSeconds = maxDurationSeconds; + return returnValue.firstOrNull; + } + + @override + Future> pickMultiVideo( + int? maxDurationSeconds, + int? limit, + ) async { + passedSelectionType = _SelectionType.multiVideo; + passedMaxDurationSeconds = maxDurationSeconds; + passedLimit = limit; + return returnValue; + } + + @override + // ignore: non_constant_identifier_names + BinaryMessenger? get pigeonVar_binaryMessenger => null; + + @override + // ignore: non_constant_identifier_names + String get pigeonVar_messageChannelSuffix => ''; +} diff --git a/packages/image_picker/image_picker_ios/test/test_api.g.dart b/packages/image_picker/image_picker_ios/test/test_api.g.dart deleted file mode 100644 index 02310e334e7..00000000000 --- a/packages/image_picker/image_picker_ios/test/test_api.g.dart +++ /dev/null @@ -1,336 +0,0 @@ -// Copyright 2013 The Flutter Authors -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// Autogenerated from Pigeon (v22.7.4), do not edit directly. -// See also: https://pub.dev/packages/pigeon -// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, unnecessary_import, no_leading_underscores_for_local_identifiers -// ignore_for_file: avoid_relative_lib_imports -import 'dart:async'; -import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; -import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; -import 'package:flutter/services.dart'; -import 'package:flutter_test/flutter_test.dart'; - -import 'package:image_picker_ios/src/messages.g.dart'; - -class _PigeonCodec extends StandardMessageCodec { - const _PigeonCodec(); - @override - void writeValue(WriteBuffer buffer, Object? value) { - if (value is int) { - buffer.putUint8(4); - buffer.putInt64(value); - } else if (value is SourceCamera) { - buffer.putUint8(129); - writeValue(buffer, value.index); - } else if (value is SourceType) { - buffer.putUint8(130); - writeValue(buffer, value.index); - } else if (value is MaxSize) { - buffer.putUint8(131); - writeValue(buffer, value.encode()); - } else if (value is MediaSelectionOptions) { - buffer.putUint8(132); - writeValue(buffer, value.encode()); - } else if (value is SourceSpecification) { - buffer.putUint8(133); - writeValue(buffer, value.encode()); - } else { - super.writeValue(buffer, value); - } - } - - @override - Object? readValueOfType(int type, ReadBuffer buffer) { - switch (type) { - case 129: - final int? value = readValue(buffer) as int?; - return value == null ? null : SourceCamera.values[value]; - case 130: - final int? value = readValue(buffer) as int?; - return value == null ? null : SourceType.values[value]; - case 131: - return MaxSize.decode(readValue(buffer)!); - case 132: - return MediaSelectionOptions.decode(readValue(buffer)!); - case 133: - return SourceSpecification.decode(readValue(buffer)!); - default: - return super.readValueOfType(type, buffer); - } - } -} - -abstract class TestHostImagePickerApi { - static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => - TestDefaultBinaryMessengerBinding.instance; - static const MessageCodec pigeonChannelCodec = _PigeonCodec(); - - Future pickImage( - SourceSpecification source, - MaxSize maxSize, - int? imageQuality, - bool requestFullMetadata, - ); - - Future> pickMultiImage( - MaxSize maxSize, - int? imageQuality, - bool requestFullMetadata, - int? limit, - ); - - Future pickVideo( - SourceSpecification source, - int? maxDurationSeconds, - ); - - Future> pickMultiVideo(int? maxDurationSeconds, int? limit); - - /// Selects images and videos and returns their paths. - Future> pickMedia(MediaSelectionOptions mediaSelectionOptions); - - static void setUp( - TestHostImagePickerApi? api, { - BinaryMessenger? binaryMessenger, - String messageChannelSuffix = '', - }) { - messageChannelSuffix = messageChannelSuffix.isNotEmpty - ? '.$messageChannelSuffix' - : ''; - { - final BasicMessageChannel - pigeonVar_channel = BasicMessageChannel( - 'dev.flutter.pigeon.image_picker_ios.ImagePickerApi.pickImage$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger, - ); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler< - Object? - >(pigeonVar_channel, (Object? message) async { - assert( - message != null, - 'Argument for dev.flutter.pigeon.image_picker_ios.ImagePickerApi.pickImage was null.', - ); - final List args = (message as List?)!; - final SourceSpecification? arg_source = - (args[0] as SourceSpecification?); - assert( - arg_source != null, - 'Argument for dev.flutter.pigeon.image_picker_ios.ImagePickerApi.pickImage was null, expected non-null SourceSpecification.', - ); - final MaxSize? arg_maxSize = (args[1] as MaxSize?); - assert( - arg_maxSize != null, - 'Argument for dev.flutter.pigeon.image_picker_ios.ImagePickerApi.pickImage was null, expected non-null MaxSize.', - ); - final int? arg_imageQuality = (args[2] as int?); - final bool? arg_requestFullMetadata = (args[3] as bool?); - assert( - arg_requestFullMetadata != null, - 'Argument for dev.flutter.pigeon.image_picker_ios.ImagePickerApi.pickImage was null, expected non-null bool.', - ); - try { - final String? output = await api.pickImage( - arg_source!, - arg_maxSize!, - arg_imageQuality, - arg_requestFullMetadata!, - ); - return [output]; - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString()), - ); - } - }); - } - } - { - final BasicMessageChannel - pigeonVar_channel = BasicMessageChannel( - 'dev.flutter.pigeon.image_picker_ios.ImagePickerApi.pickMultiImage$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger, - ); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler< - Object? - >(pigeonVar_channel, (Object? message) async { - assert( - message != null, - 'Argument for dev.flutter.pigeon.image_picker_ios.ImagePickerApi.pickMultiImage was null.', - ); - final List args = (message as List?)!; - final MaxSize? arg_maxSize = (args[0] as MaxSize?); - assert( - arg_maxSize != null, - 'Argument for dev.flutter.pigeon.image_picker_ios.ImagePickerApi.pickMultiImage was null, expected non-null MaxSize.', - ); - final int? arg_imageQuality = (args[1] as int?); - final bool? arg_requestFullMetadata = (args[2] as bool?); - assert( - arg_requestFullMetadata != null, - 'Argument for dev.flutter.pigeon.image_picker_ios.ImagePickerApi.pickMultiImage was null, expected non-null bool.', - ); - final int? arg_limit = (args[3] as int?); - try { - final List output = await api.pickMultiImage( - arg_maxSize!, - arg_imageQuality, - arg_requestFullMetadata!, - arg_limit, - ); - return [output]; - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString()), - ); - } - }); - } - } - { - final BasicMessageChannel - pigeonVar_channel = BasicMessageChannel( - 'dev.flutter.pigeon.image_picker_ios.ImagePickerApi.pickVideo$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger, - ); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, ( - Object? message, - ) async { - assert( - message != null, - 'Argument for dev.flutter.pigeon.image_picker_ios.ImagePickerApi.pickVideo was null.', - ); - final List args = (message as List?)!; - final SourceSpecification? arg_source = - (args[0] as SourceSpecification?); - assert( - arg_source != null, - 'Argument for dev.flutter.pigeon.image_picker_ios.ImagePickerApi.pickVideo was null, expected non-null SourceSpecification.', - ); - final int? arg_maxDurationSeconds = (args[1] as int?); - try { - final String? output = await api.pickVideo( - arg_source!, - arg_maxDurationSeconds, - ); - return [output]; - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException( - code: 'error', - message: e.toString(), - ), - ); - } - }); - } - } - { - final BasicMessageChannel - pigeonVar_channel = BasicMessageChannel( - 'dev.flutter.pigeon.image_picker_ios.ImagePickerApi.pickMultiVideo$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger, - ); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, ( - Object? message, - ) async { - assert( - message != null, - 'Argument for dev.flutter.pigeon.image_picker_ios.ImagePickerApi.pickMultiVideo was null.', - ); - final List args = (message as List?)!; - final int? arg_maxDurationSeconds = (args[0] as int?); - final int? arg_limit = (args[1] as int?); - try { - final List output = await api.pickMultiVideo( - arg_maxDurationSeconds, - arg_limit, - ); - return [output]; - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException( - code: 'error', - message: e.toString(), - ), - ); - } - }); - } - } - { - final BasicMessageChannel - pigeonVar_channel = BasicMessageChannel( - 'dev.flutter.pigeon.image_picker_ios.ImagePickerApi.pickMedia$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger, - ); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, ( - Object? message, - ) async { - assert( - message != null, - 'Argument for dev.flutter.pigeon.image_picker_ios.ImagePickerApi.pickMedia was null.', - ); - final List args = (message as List?)!; - final MediaSelectionOptions? arg_mediaSelectionOptions = - (args[0] as MediaSelectionOptions?); - assert( - arg_mediaSelectionOptions != null, - 'Argument for dev.flutter.pigeon.image_picker_ios.ImagePickerApi.pickMedia was null, expected non-null MediaSelectionOptions.', - ); - try { - final List output = await api.pickMedia( - arg_mediaSelectionOptions!, - ); - return [output]; - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException( - code: 'error', - message: e.toString(), - ), - ); - } - }); - } - } - } -}