diff --git a/packages/image_picker/image_picker/CHANGELOG.md b/packages/image_picker/image_picker/CHANGELOG.md index 8c8f1d4a29c..218c09bca86 100644 --- a/packages/image_picker/image_picker/CHANGELOG.md +++ b/packages/image_picker/image_picker/CHANGELOG.md @@ -1,3 +1,7 @@ +## NEXT + +* Updates minimum supported SDK version to Flutter 3.29/Dart 3.7. + ## 1.2.0 * Adds `pickMultiVideo` to allow selecting multiple videos from the gallery. diff --git a/packages/image_picker/image_picker/README.md b/packages/image_picker/image_picker/README.md index 866adf58118..59bd065a2ae 100755 --- a/packages/image_picker/image_picker/README.md +++ b/packages/image_picker/image_picker/README.md @@ -124,16 +124,18 @@ import 'package:image_picker_platform_interface/image_picker_platform_interface. // ยทยทยท class MyCameraDelegate extends ImagePickerCameraDelegate { @override - Future takePhoto( - {ImagePickerCameraDelegateOptions options = - const ImagePickerCameraDelegateOptions()}) async { + Future takePhoto({ + ImagePickerCameraDelegateOptions options = + const ImagePickerCameraDelegateOptions(), + }) async { return _takeAPhoto(options.preferredCameraDevice); } @override - Future takeVideo( - {ImagePickerCameraDelegateOptions options = - const ImagePickerCameraDelegateOptions()}) async { + Future takeVideo({ + ImagePickerCameraDelegateOptions options = + const ImagePickerCameraDelegateOptions(), + }) async { return _takeAVideo(options.preferredCameraDevice); } } @@ -172,8 +174,9 @@ final XFile? image = await picker.pickImage(source: ImageSource.gallery); // Capture a photo. final XFile? photo = await picker.pickImage(source: ImageSource.camera); // Pick a video. -final XFile? galleryVideo = - await picker.pickVideo(source: ImageSource.gallery); +final XFile? galleryVideo = await picker.pickVideo( + source: ImageSource.gallery, +); // Capture a video. final XFile? cameraVideo = await picker.pickVideo(source: ImageSource.camera); // Pick multiple images. diff --git a/packages/image_picker/image_picker/example/lib/main.dart b/packages/image_picker/image_picker/example/lib/main.dart index f1ec8b76341..4ad97599f3a 100755 --- a/packages/image_picker/image_picker/example/lib/main.dart +++ b/packages/image_picker/image_picker/example/lib/main.dart @@ -98,28 +98,35 @@ class _MyHomePageState extends State { files = await _picker.pickMultiVideo(); } else { final XFile? file = await _picker.pickVideo( - source: source, maxDuration: const Duration(seconds: 10)); + source: source, + maxDuration: const Duration(seconds: 10), + ); files = [if (file != null) file]; } // Just play the first file, to keep the example simple. await _playVideo(files.firstOrNull); } else if (allowMultiple) { - await _displayPickImageDialog(context, true, (double? maxWidth, - double? maxHeight, int? quality, int? limit) async { + await _displayPickImageDialog(context, true, ( + double? maxWidth, + double? maxHeight, + int? quality, + int? limit, + ) async { try { - final List pickedFileList = isMedia - ? await _picker.pickMultipleMedia( - maxWidth: maxWidth, - maxHeight: maxHeight, - imageQuality: quality, - limit: limit, - ) - : await _picker.pickMultiImage( - maxWidth: maxWidth, - maxHeight: maxHeight, - imageQuality: quality, - limit: limit, - ); + final List pickedFileList = + isMedia + ? await _picker.pickMultipleMedia( + maxWidth: maxWidth, + maxHeight: maxHeight, + imageQuality: quality, + limit: limit, + ) + : await _picker.pickMultiImage( + maxWidth: maxWidth, + maxHeight: maxHeight, + imageQuality: quality, + limit: limit, + ); setState(() { _mediaFileList = pickedFileList; }); @@ -130,8 +137,12 @@ class _MyHomePageState extends State { } }); } else if (isMedia) { - await _displayPickImageDialog(context, false, (double? maxWidth, - double? maxHeight, int? quality, int? limit) async { + await _displayPickImageDialog(context, false, ( + double? maxWidth, + double? maxHeight, + int? quality, + int? limit, + ) async { try { final List pickedFileList = []; final XFile? media = await _picker.pickMedia( @@ -152,8 +163,12 @@ class _MyHomePageState extends State { } }); } else { - await _displayPickImageDialog(context, false, (double? maxWidth, - double? maxHeight, int? quality, int? limit) async { + await _displayPickImageDialog(context, false, ( + double? maxWidth, + double? maxHeight, + int? quality, + int? limit, + ) async { try { final XFile? pickedFile = await _picker.pickImage( source: source, @@ -234,19 +249,23 @@ class _MyHomePageState extends State { // See https://pub.dev/packages/image_picker_for_web#limitations-on-the-web-platform return Semantics( label: 'image_picker_example_picked_image', - child: kIsWeb - ? Image.network(_mediaFileList![index].path) - : (mime == null || mime.startsWith('image/') - ? Image.file( - File(_mediaFileList![index].path), - errorBuilder: (BuildContext context, Object error, - StackTrace? stackTrace) { - return const Center( - child: - Text('This image type is not supported')); - }, - ) - : _buildInlineVideoPlayer(index)), + child: + kIsWeb + ? Image.network(_mediaFileList![index].path) + : (mime == null || mime.startsWith('image/') + ? Image.file( + File(_mediaFileList![index].path), + errorBuilder: ( + BuildContext context, + Object error, + StackTrace? stackTrace, + ) { + return const Center( + child: Text('This image type is not supported'), + ); + }, + ) + : _buildInlineVideoPlayer(index)), ); }, itemCount: _mediaFileList!.length, @@ -266,8 +285,9 @@ class _MyHomePageState extends State { } Widget _buildInlineVideoPlayer(int index) { - final VideoPlayerController controller = - VideoPlayerController.file(File(_mediaFileList![index].path)); + final VideoPlayerController controller = VideoPlayerController.file( + File(_mediaFileList![index].path), + ); const double volume = kIsWeb ? 0.0 : 1.0; controller.setVolume(volume); controller.initialize(); @@ -311,39 +331,41 @@ class _MyHomePageState extends State { @override Widget build(BuildContext context) { return Scaffold( - appBar: AppBar( - title: Text(widget.title!), - ), + appBar: AppBar(title: Text(widget.title!)), body: Center( - child: !kIsWeb && defaultTargetPlatform == TargetPlatform.android - ? FutureBuilder( - future: retrieveLostData(), - builder: (BuildContext context, AsyncSnapshot snapshot) { - switch (snapshot.connectionState) { - case ConnectionState.none: - case ConnectionState.waiting: - return const Text( - 'You have not yet picked an image.', - textAlign: TextAlign.center, - ); - case ConnectionState.done: - return _handlePreview(); - case ConnectionState.active: - if (snapshot.hasError) { - return Text( - 'Pick image/video error: ${snapshot.error}}', - textAlign: TextAlign.center, - ); - } else { + child: + !kIsWeb && defaultTargetPlatform == TargetPlatform.android + ? FutureBuilder( + future: retrieveLostData(), + builder: ( + BuildContext context, + AsyncSnapshot snapshot, + ) { + switch (snapshot.connectionState) { + case ConnectionState.none: + case ConnectionState.waiting: return const Text( 'You have not yet picked an image.', textAlign: TextAlign.center, ); - } - } - }, - ) - : _handlePreview(), + case ConnectionState.done: + return _handlePreview(); + case ConnectionState.active: + if (snapshot.hasError) { + return Text( + 'Pick image/video error: ${snapshot.error}}', + textAlign: TextAlign.center, + ); + } else { + return const Text( + 'You have not yet picked an image.', + textAlign: TextAlign.center, + ); + } + } + }, + ) + : _handlePreview(), ), floatingActionButton: Column( mainAxisAlignment: MainAxisAlignment.end, @@ -441,8 +463,11 @@ class _MyHomePageState extends State { backgroundColor: Colors.red, onPressed: () { isVideo = true; - _onImageButtonPressed(ImageSource.gallery, - context: context, allowMultiple: true); + _onImageButtonPressed( + ImageSource.gallery, + context: context, + allowMultiple: true, + ); }, heroTag: 'multiVideo', tooltip: 'Pick multiple videos', @@ -478,77 +503,97 @@ class _MyHomePageState extends State { } Future _displayPickImageDialog( - BuildContext context, bool isMulti, OnPickImageCallback onPick) async { + BuildContext context, + bool isMulti, + OnPickImageCallback onPick, + ) async { return showDialog( - context: context, - builder: (BuildContext context) { - return AlertDialog( - title: const Text('Add optional parameters'), - content: Column( - mainAxisSize: MainAxisSize.min, - children: [ - TextField( - controller: maxWidthController, - keyboardType: - const TextInputType.numberWithOptions(decimal: true), - decoration: const InputDecoration( - hintText: 'Enter maxWidth if desired'), + context: context, + builder: (BuildContext context) { + return AlertDialog( + title: const Text('Add optional parameters'), + content: Column( + mainAxisSize: MainAxisSize.min, + children: [ + TextField( + controller: maxWidthController, + keyboardType: const TextInputType.numberWithOptions( + decimal: true, ), - TextField( - controller: maxHeightController, - keyboardType: - const TextInputType.numberWithOptions(decimal: true), - decoration: const InputDecoration( - hintText: 'Enter maxHeight if desired'), + decoration: const InputDecoration( + hintText: 'Enter maxWidth if desired', + ), + ), + TextField( + controller: maxHeightController, + keyboardType: const TextInputType.numberWithOptions( + decimal: true, + ), + decoration: const InputDecoration( + hintText: 'Enter maxHeight if desired', + ), + ), + TextField( + controller: qualityController, + keyboardType: TextInputType.number, + decoration: const InputDecoration( + hintText: 'Enter quality if desired', ), + ), + if (isMulti) TextField( - controller: qualityController, + controller: limitController, keyboardType: TextInputType.number, decoration: const InputDecoration( - hintText: 'Enter quality if desired'), - ), - if (isMulti) - TextField( - controller: limitController, - keyboardType: TextInputType.number, - decoration: const InputDecoration( - hintText: 'Enter limit if desired'), + hintText: 'Enter limit if desired', ), - ], + ), + ], + ), + actions: [ + TextButton( + child: const Text('CANCEL'), + onPressed: () { + Navigator.of(context).pop(); + }, ), - actions: [ - TextButton( - child: const Text('CANCEL'), - onPressed: () { - Navigator.of(context).pop(); - }, - ), - TextButton( - child: const Text('PICK'), - onPressed: () { - final double? width = maxWidthController.text.isNotEmpty + TextButton( + child: const Text('PICK'), + onPressed: () { + final double? width = + maxWidthController.text.isNotEmpty ? double.parse(maxWidthController.text) : null; - final double? height = maxHeightController.text.isNotEmpty + final double? height = + maxHeightController.text.isNotEmpty ? double.parse(maxHeightController.text) : null; - final int? quality = qualityController.text.isNotEmpty + final int? quality = + qualityController.text.isNotEmpty ? int.parse(qualityController.text) : null; - final int? limit = limitController.text.isNotEmpty + final int? limit = + limitController.text.isNotEmpty ? int.parse(limitController.text) : null; - onPick(width, height, quality, limit); - Navigator.of(context).pop(); - }), - ], - ); - }); + onPick(width, height, quality, limit); + Navigator.of(context).pop(); + }, + ), + ], + ); + }, + ); } } -typedef OnPickImageCallback = void Function( - double? maxWidth, double? maxHeight, int? quality, int? limit); +typedef OnPickImageCallback = + void Function( + double? maxWidth, + double? maxHeight, + int? quality, + int? limit, + ); class AspectRatioVideo extends StatefulWidget { const AspectRatioVideo(this.controller, {super.key}); diff --git a/packages/image_picker/image_picker/example/lib/readme_excerpts.dart b/packages/image_picker/image_picker/example/lib/readme_excerpts.dart index 15c8185ecf6..9451228070d 100644 --- a/packages/image_picker/image_picker/example/lib/readme_excerpts.dart +++ b/packages/image_picker/image_picker/example/lib/readme_excerpts.dart @@ -12,16 +12,18 @@ import 'package:image_picker_platform_interface/image_picker_platform_interface. // #docregion CameraDelegate class MyCameraDelegate extends ImagePickerCameraDelegate { @override - Future takePhoto( - {ImagePickerCameraDelegateOptions options = - const ImagePickerCameraDelegateOptions()}) async { + Future takePhoto({ + ImagePickerCameraDelegateOptions options = + const ImagePickerCameraDelegateOptions(), + }) async { return _takeAPhoto(options.preferredCameraDevice); } @override - Future takeVideo( - {ImagePickerCameraDelegateOptions options = - const ImagePickerCameraDelegateOptions()}) async { + Future takeVideo({ + ImagePickerCameraDelegateOptions options = + const ImagePickerCameraDelegateOptions(), + }) async { return _takeAVideo(options.preferredCameraDevice); } } @@ -36,8 +38,9 @@ Future> readmePickExample() async { // Capture a photo. final XFile? photo = await picker.pickImage(source: ImageSource.camera); // Pick a video. - final XFile? galleryVideo = - await picker.pickVideo(source: ImageSource.gallery); + final XFile? galleryVideo = await picker.pickVideo( + source: ImageSource.gallery, + ); // Capture a video. final XFile? cameraVideo = await picker.pickVideo(source: ImageSource.camera); // Pick multiple images. diff --git a/packages/image_picker/image_picker/example/pubspec.yaml b/packages/image_picker/image_picker/example/pubspec.yaml index b69c9124cea..6b736e428b6 100644 --- a/packages/image_picker/image_picker/example/pubspec.yaml +++ b/packages/image_picker/image_picker/example/pubspec.yaml @@ -3,8 +3,8 @@ description: Demonstrates how to use the image_picker plugin. publish_to: none environment: - sdk: ^3.6.0 - flutter: ">=3.27.0" + sdk: ^3.7.0 + flutter: ">=3.29.0" dependencies: flutter: diff --git a/packages/image_picker/image_picker/example/test/readme_excerpts_test.dart b/packages/image_picker/image_picker/example/test/readme_excerpts_test.dart index 512438ce2b5..6a243632334 100644 --- a/packages/image_picker/image_picker/example/test/readme_excerpts_test.dart +++ b/packages/image_picker/image_picker/example/test/readme_excerpts_test.dart @@ -20,8 +20,10 @@ void main() { expect(results.length, greaterThan(4)); // And the calls should all be different. This works since each fake call // returns a different result. - expect(results.map((XFile? file) => file?.path).toSet().length, - results.length); + expect( + results.map((XFile? file) => file?.path).toSet().length, + results.length, + ); }); test('sanity check getLostData', () async { @@ -32,9 +34,10 @@ void main() { class FakeImagePicker extends ImagePickerPlatform { @override - Future getImageFromSource( - {required ImageSource source, - ImagePickerOptions options = const ImagePickerOptions()}) async { + Future getImageFromSource({ + required ImageSource source, + ImagePickerOptions options = const ImagePickerOptions(), + }) async { return XFile(source == ImageSource.camera ? 'cameraImage' : 'galleryImage'); } @@ -44,9 +47,9 @@ class FakeImagePicker extends ImagePickerPlatform { } @override - Future> getMultiImageWithOptions( - {MultiImagePickerOptions options = - const MultiImagePickerOptions()}) async { + Future> getMultiImageWithOptions({ + MultiImagePickerOptions options = const MultiImagePickerOptions(), + }) async { return [XFile('multiImage')]; } @@ -58,10 +61,11 @@ class FakeImagePicker extends ImagePickerPlatform { } @override - Future getVideo( - {required ImageSource source, - CameraDevice preferredCameraDevice = CameraDevice.rear, - Duration? maxDuration}) async { + Future getVideo({ + required ImageSource source, + CameraDevice preferredCameraDevice = CameraDevice.rear, + Duration? maxDuration, + }) async { return XFile(source == ImageSource.camera ? 'cameraVideo' : 'galleryVideo'); } } diff --git a/packages/image_picker/image_picker/lib/image_picker.dart b/packages/image_picker/image_picker/lib/image_picker.dart index b5473d6f0eb..62e87aa52e8 100755 --- a/packages/image_picker/image_picker/lib/image_picker.dart +++ b/packages/image_picker/image_picker/lib/image_picker.dart @@ -79,12 +79,12 @@ class ImagePicker { }) { final ImagePickerOptions imagePickerOptions = ImagePickerOptions.createAndValidate( - maxWidth: maxWidth, - maxHeight: maxHeight, - imageQuality: imageQuality, - preferredCameraDevice: preferredCameraDevice, - requestFullMetadata: requestFullMetadata, - ); + maxWidth: maxWidth, + maxHeight: maxHeight, + imageQuality: imageQuality, + preferredCameraDevice: preferredCameraDevice, + requestFullMetadata: requestFullMetadata, + ); return platform.getImageFromSource( source: source, @@ -314,15 +314,9 @@ class ImagePicker { /// /// The method can throw a [PlatformException] if the video selection process /// fails. - Future> pickMultiVideo({ - Duration? maxDuration, - int? limit, - }) { + Future> pickMultiVideo({Duration? maxDuration, int? limit}) { return platform.getMultiVideoWithOptions( - options: MultiVideoPickerOptions( - maxDuration: maxDuration, - limit: limit, - ), + options: MultiVideoPickerOptions(maxDuration: maxDuration, limit: limit), ); } diff --git a/packages/image_picker/image_picker/pubspec.yaml b/packages/image_picker/image_picker/pubspec.yaml index 28cef5b855e..1fe3b870196 100755 --- a/packages/image_picker/image_picker/pubspec.yaml +++ b/packages/image_picker/image_picker/pubspec.yaml @@ -6,8 +6,8 @@ issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+ version: 1.2.0 environment: - sdk: ^3.6.0 - flutter: ">=3.27.0" + sdk: ^3.7.0 + flutter: ">=3.29.0" flutter: plugin: diff --git a/packages/image_picker/image_picker/test/image_picker_test.dart b/packages/image_picker/image_picker/test/image_picker_test.dart index 9613d29f1d2..8b5fd536571 100644 --- a/packages/image_picker/image_picker/test/image_picker_test.dart +++ b/packages/image_picker/image_picker/test/image_picker_test.dart @@ -16,8 +16,10 @@ import 'image_picker_test.mocks.dart' as base_mock; class _MockImagePickerPlatform extends base_mock.MockImagePickerPlatform with MockPlatformInterfaceMixin {} -@GenerateMocks([], - customMocks: >[MockSpec()]) +@GenerateMocks( + [], + customMocks: >[MockSpec()], +) void main() { group('ImagePicker', () { late _MockImagePickerPlatform mockPlatform; @@ -30,9 +32,12 @@ void main() { group('#Single image/video', () { group('#pickImage', () { setUp(() { - when(mockPlatform.getImageFromSource( - source: anyNamed('source'), options: anyNamed('options'))) - .thenAnswer((Invocation _) async => null); + when( + mockPlatform.getImageFromSource( + source: anyNamed('source'), + options: anyNamed('options'), + ), + ).thenAnswer((Invocation _) async => null); }); test('passes the image source argument correctly', () async { @@ -61,42 +66,50 @@ void main() { test('passes the width and height arguments correctly', () async { final ImagePicker picker = ImagePicker(); await picker.pickImage(source: ImageSource.camera); + await picker.pickImage(source: ImageSource.camera, maxWidth: 10.0); + await picker.pickImage(source: ImageSource.camera, maxHeight: 10.0); + 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, ); - 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); verifyInOrder([ mockPlatform.getImageFromSource( source: ImageSource.camera, options: argThat( isInstanceOf() - .having((ImagePickerOptions options) => options.maxWidth, - 'maxWidth', isNull) - .having((ImagePickerOptions options) => options.maxHeight, - 'maxHeight', isNull) .having( - (ImagePickerOptions options) => options.imageQuality, - 'imageQuality', - isNull), + (ImagePickerOptions options) => options.maxWidth, + 'maxWidth', + isNull, + ) + .having( + (ImagePickerOptions options) => options.maxHeight, + 'maxHeight', + isNull, + ) + .having( + (ImagePickerOptions options) => options.imageQuality, + 'imageQuality', + isNull, + ), named: 'options', ), ), @@ -104,14 +117,21 @@ void main() { source: ImageSource.camera, options: argThat( isInstanceOf() - .having((ImagePickerOptions options) => options.maxWidth, - 'maxWidth', equals(10.0)) - .having((ImagePickerOptions options) => options.maxHeight, - 'maxHeight', isNull) .having( - (ImagePickerOptions options) => options.imageQuality, - 'imageQuality', - isNull), + (ImagePickerOptions options) => options.maxWidth, + 'maxWidth', + equals(10.0), + ) + .having( + (ImagePickerOptions options) => options.maxHeight, + 'maxHeight', + isNull, + ) + .having( + (ImagePickerOptions options) => options.imageQuality, + 'imageQuality', + isNull, + ), named: 'options', ), ), @@ -119,14 +139,21 @@ void main() { source: ImageSource.camera, options: argThat( isInstanceOf() - .having((ImagePickerOptions options) => options.maxWidth, - 'maxWidth', isNull) - .having((ImagePickerOptions options) => options.maxHeight, - 'maxHeight', equals(10.0)) .having( - (ImagePickerOptions options) => options.imageQuality, - 'imageQuality', - isNull), + (ImagePickerOptions options) => options.maxWidth, + 'maxWidth', + isNull, + ) + .having( + (ImagePickerOptions options) => options.maxHeight, + 'maxHeight', + equals(10.0), + ) + .having( + (ImagePickerOptions options) => options.imageQuality, + 'imageQuality', + isNull, + ), named: 'options', ), ), @@ -134,14 +161,21 @@ void main() { source: ImageSource.camera, options: argThat( isInstanceOf() - .having((ImagePickerOptions options) => options.maxWidth, - 'maxWidth', equals(10.0)) - .having((ImagePickerOptions options) => options.maxHeight, - 'maxHeight', equals(20.0)) .having( - (ImagePickerOptions options) => options.imageQuality, - 'imageQuality', - isNull), + (ImagePickerOptions options) => options.maxWidth, + 'maxWidth', + equals(10.0), + ) + .having( + (ImagePickerOptions options) => options.maxHeight, + 'maxHeight', + equals(20.0), + ) + .having( + (ImagePickerOptions options) => options.imageQuality, + 'imageQuality', + isNull, + ), named: 'options', ), ), @@ -149,14 +183,21 @@ void main() { source: ImageSource.camera, options: argThat( isInstanceOf() - .having((ImagePickerOptions options) => options.maxWidth, - 'maxWidth', equals(10.0)) - .having((ImagePickerOptions options) => options.maxHeight, - 'maxHeight', isNull) .having( - (ImagePickerOptions options) => options.imageQuality, - 'imageQuality', - equals(70)), + (ImagePickerOptions options) => options.maxWidth, + 'maxWidth', + equals(10.0), + ) + .having( + (ImagePickerOptions options) => options.maxHeight, + 'maxHeight', + isNull, + ) + .having( + (ImagePickerOptions options) => options.imageQuality, + 'imageQuality', + equals(70), + ), named: 'options', ), ), @@ -164,14 +205,21 @@ void main() { source: ImageSource.camera, options: argThat( isInstanceOf() - .having((ImagePickerOptions options) => options.maxWidth, - 'maxWidth', isNull) - .having((ImagePickerOptions options) => options.maxHeight, - 'maxHeight', equals(10.0)) .having( - (ImagePickerOptions options) => options.imageQuality, - 'imageQuality', - equals(70)), + (ImagePickerOptions options) => options.maxWidth, + 'maxWidth', + isNull, + ) + .having( + (ImagePickerOptions options) => options.maxHeight, + 'maxHeight', + equals(10.0), + ) + .having( + (ImagePickerOptions options) => options.imageQuality, + 'imageQuality', + equals(70), + ), named: 'options', ), ), @@ -179,14 +227,21 @@ void main() { source: ImageSource.camera, options: argThat( isInstanceOf() - .having((ImagePickerOptions options) => options.maxWidth, - 'maxWidth', equals(10.0)) - .having((ImagePickerOptions options) => options.maxHeight, - 'maxHeight', equals(20.0)) .having( - (ImagePickerOptions options) => options.imageQuality, - 'imageQuality', - equals(70)), + (ImagePickerOptions options) => options.maxWidth, + 'maxWidth', + equals(10.0), + ) + .having( + (ImagePickerOptions options) => options.maxHeight, + 'maxHeight', + equals(20.0), + ) + .having( + (ImagePickerOptions options) => options.imageQuality, + 'imageQuality', + equals(70), + ), named: 'options', ), ), @@ -217,50 +272,60 @@ void main() { final ImagePicker picker = ImagePicker(); await picker.pickImage(source: ImageSource.camera); - verify(mockPlatform.getImageFromSource( - source: ImageSource.camera, - options: argThat( - isInstanceOf().having( + verify( + mockPlatform.getImageFromSource( + source: ImageSource.camera, + options: argThat( + isInstanceOf().having( (ImagePickerOptions options) => options.preferredCameraDevice, 'preferredCameraDevice', - equals(CameraDevice.rear)), - named: 'options', + equals(CameraDevice.rear), + ), + named: 'options', + ), ), - )); + ); }); test('camera position can set to front', () async { final ImagePicker picker = ImagePicker(); await picker.pickImage( - source: ImageSource.camera, - preferredCameraDevice: CameraDevice.front); - - verify(mockPlatform.getImageFromSource( source: ImageSource.camera, - options: argThat( - isInstanceOf().having( + preferredCameraDevice: CameraDevice.front, + ); + + verify( + mockPlatform.getImageFromSource( + source: ImageSource.camera, + options: argThat( + isInstanceOf().having( (ImagePickerOptions options) => options.preferredCameraDevice, 'preferredCameraDevice', - equals(CameraDevice.front)), - named: 'options', + equals(CameraDevice.front), + ), + named: 'options', + ), ), - )); + ); }); test('full metadata argument defaults to true', () async { final ImagePicker picker = ImagePicker(); await picker.pickImage(source: ImageSource.gallery); - verify(mockPlatform.getImageFromSource( - source: ImageSource.gallery, - options: argThat( - isInstanceOf().having( + verify( + mockPlatform.getImageFromSource( + source: ImageSource.gallery, + options: argThat( + isInstanceOf().having( (ImagePickerOptions options) => options.requestFullMetadata, 'requestFullMetadata', - isTrue), - named: 'options', + isTrue, + ), + named: 'options', + ), ), - )); + ); }); test('passes the full metadata argument correctly', () async { @@ -270,26 +335,31 @@ void main() { requestFullMetadata: false, ); - verify(mockPlatform.getImageFromSource( - source: ImageSource.gallery, - options: argThat( - isInstanceOf().having( + verify( + mockPlatform.getImageFromSource( + source: ImageSource.gallery, + options: argThat( + isInstanceOf().having( (ImagePickerOptions options) => options.requestFullMetadata, 'requestFullMetadata', - isFalse), - named: 'options', + isFalse, + ), + named: 'options', + ), ), - )); + ); }); }); group('#pickVideo', () { setUp(() { - when(mockPlatform.getVideo( - source: anyNamed('source'), - preferredCameraDevice: anyNamed('preferredCameraDevice'), - maxDuration: anyNamed('maxDuration'))) - .thenAnswer((Invocation _) async => null); + when( + mockPlatform.getVideo( + source: anyNamed('source'), + preferredCameraDevice: anyNamed('preferredCameraDevice'), + maxDuration: anyNamed('maxDuration'), + ), + ).thenAnswer((Invocation _) async => null); }); test('passes the image source argument correctly', () async { @@ -307,14 +377,16 @@ void main() { final ImagePicker picker = ImagePicker(); await picker.pickVideo(source: ImageSource.camera); await picker.pickVideo( - source: ImageSource.camera, - maxDuration: const Duration(seconds: 10)); + source: ImageSource.camera, + maxDuration: const Duration(seconds: 10), + ); verifyInOrder([ mockPlatform.getVideo(source: ImageSource.camera), mockPlatform.getVideo( - source: ImageSource.camera, - maxDuration: const Duration(seconds: 10)), + source: ImageSource.camera, + maxDuration: const Duration(seconds: 10), + ), ]); }); @@ -335,12 +407,16 @@ void main() { test('camera position can set to front', () async { final ImagePicker picker = ImagePicker(); await picker.pickVideo( - source: ImageSource.camera, - preferredCameraDevice: CameraDevice.front); + source: ImageSource.camera, + preferredCameraDevice: CameraDevice.front, + ); - verify(mockPlatform.getVideo( + verify( + mockPlatform.getVideo( source: ImageSource.camera, - preferredCameraDevice: CameraDevice.front)); + preferredCameraDevice: CameraDevice.front, + ), + ); }); }); @@ -348,11 +424,13 @@ void main() { test('retrieveLostData get success response', () async { final ImagePicker picker = ImagePicker(); final XFile lostFile = XFile('/example/path'); - when(mockPlatform.getLostData()).thenAnswer((Invocation _) async => - LostDataResponse( - file: lostFile, - files: [lostFile], - type: RetrieveType.image)); + when(mockPlatform.getLostData()).thenAnswer( + (Invocation _) async => LostDataResponse( + file: lostFile, + files: [lostFile], + type: RetrieveType.image, + ), + ); final LostDataResponse response = await picker.retrieveLostData(); @@ -360,35 +438,43 @@ void main() { expect(response.file!.path, '/example/path'); }); - test('retrieveLostData should successfully retrieve multiple files', - () async { - final ImagePicker picker = ImagePicker(); - final List lostFiles = [ - XFile('/example/path0'), - XFile('/example/path1'), - ]; - when(mockPlatform.getLostData()).thenAnswer((Invocation _) async => - LostDataResponse( - file: lostFiles.last, - files: lostFiles, - type: RetrieveType.image)); + test( + 'retrieveLostData should successfully retrieve multiple files', + () async { + final ImagePicker picker = ImagePicker(); + final List lostFiles = [ + XFile('/example/path0'), + XFile('/example/path1'), + ]; + when(mockPlatform.getLostData()).thenAnswer( + (Invocation _) async => LostDataResponse( + file: lostFiles.last, + files: lostFiles, + type: RetrieveType.image, + ), + ); - final LostDataResponse response = await picker.retrieveLostData(); + final LostDataResponse response = await picker.retrieveLostData(); - expect(response.type, RetrieveType.image); - expect(response.file, isNotNull); - expect(response.file!.path, '/example/path1'); - expect(response.files!.first.path, '/example/path0'); - expect(response.files!.length, 2); - }); + expect(response.type, RetrieveType.image); + expect(response.file, isNotNull); + expect(response.file!.path, '/example/path1'); + expect(response.files!.first.path, '/example/path0'); + expect(response.files!.length, 2); + }, + ); test('retrieveLostData get error response', () async { final ImagePicker picker = ImagePicker(); - when(mockPlatform.getLostData()).thenAnswer((Invocation _) async => - LostDataResponse( - exception: PlatformException( - code: 'test_error_code', message: 'test_error_message'), - type: RetrieveType.video)); + when(mockPlatform.getLostData()).thenAnswer( + (Invocation _) async => LostDataResponse( + exception: PlatformException( + code: 'test_error_code', + message: 'test_error_message', + ), + type: RetrieveType.video, + ), + ); final LostDataResponse response = await picker.retrieveLostData(); @@ -400,9 +486,9 @@ void main() { group('#pickMultiVideo', () { setUp(() { - when(mockPlatform.getMultiVideoWithOptions( - options: anyNamed('options'), - )).thenAnswer((Invocation _) async => []); + when( + mockPlatform.getMultiVideoWithOptions(options: anyNamed('options')), + ).thenAnswer((Invocation _) async => []); }); test('passes the arguments correctly', () async { @@ -413,26 +499,31 @@ void main() { verifyInOrder([ mockPlatform.getMultiVideoWithOptions( - options: argThat( - isInstanceOf(), - named: 'options', - )), + options: argThat( + isInstanceOf(), + named: 'options', + ), + ), mockPlatform.getMultiVideoWithOptions( - options: argThat( - isInstanceOf().having( + options: argThat( + isInstanceOf().having( (MultiVideoPickerOptions options) => options.maxDuration, 'maxDuration', - equals(const Duration(seconds: 10))), - named: 'options', - )), + equals(const Duration(seconds: 10)), + ), + named: 'options', + ), + ), mockPlatform.getMultiVideoWithOptions( - options: argThat( - isInstanceOf().having( + options: argThat( + isInstanceOf().having( (MultiVideoPickerOptions options) => options.limit, 'limit', - equals(5)), - named: 'options', - )), + equals(5), + ), + named: 'options', + ), + ), ]); }); }); @@ -441,9 +532,7 @@ void main() { group('#Multi images', () { setUp(() { when( - mockPlatform.getMultiImageWithOptions( - options: anyNamed('options'), - ), + mockPlatform.getMultiImageWithOptions(options: anyNamed('options')), ).thenAnswer((Invocation _) async => []); }); @@ -451,24 +540,11 @@ void main() { test('passes the width and height arguments correctly', () async { final ImagePicker picker = ImagePicker(); 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); + 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, @@ -491,20 +567,22 @@ void main() { mockPlatform.getMultiImageWithOptions( options: argThat( isInstanceOf().having( - (MultiImagePickerOptions options) => - options.imageOptions.maxWidth, - 'maxWidth', - equals(10.0)), + (MultiImagePickerOptions options) => + options.imageOptions.maxWidth, + 'maxWidth', + equals(10.0), + ), named: 'options', ), ), mockPlatform.getMultiImageWithOptions( options: argThat( isInstanceOf().having( - (MultiImagePickerOptions options) => - options.imageOptions.maxHeight, - 'maxHeight', - equals(10.0)), + (MultiImagePickerOptions options) => + options.imageOptions.maxHeight, + 'maxHeight', + equals(10.0), + ), named: 'options', ), ), @@ -512,15 +590,17 @@ void main() { options: argThat( isInstanceOf() .having( - (MultiImagePickerOptions options) => - options.imageOptions.maxWidth, - 'maxWidth', - equals(10.0)) + (MultiImagePickerOptions options) => + options.imageOptions.maxWidth, + 'maxWidth', + equals(10.0), + ) .having( - (MultiImagePickerOptions options) => - options.imageOptions.maxHeight, - 'maxHeight', - equals(20.0)), + (MultiImagePickerOptions options) => + options.imageOptions.maxHeight, + 'maxHeight', + equals(20.0), + ), named: 'options', ), ), @@ -528,15 +608,17 @@ void main() { options: argThat( isInstanceOf() .having( - (MultiImagePickerOptions options) => - options.imageOptions.maxWidth, - 'maxWidth', - equals(10.0)) + (MultiImagePickerOptions options) => + options.imageOptions.maxWidth, + 'maxWidth', + equals(10.0), + ) .having( - (MultiImagePickerOptions options) => - options.imageOptions.imageQuality, - 'imageQuality', - equals(70)), + (MultiImagePickerOptions options) => + options.imageOptions.imageQuality, + 'imageQuality', + equals(70), + ), named: 'options', ), ), @@ -544,15 +626,17 @@ void main() { options: argThat( isInstanceOf() .having( - (MultiImagePickerOptions options) => - options.imageOptions.maxHeight, - 'maxHeight', - equals(10.0)) + (MultiImagePickerOptions options) => + options.imageOptions.maxHeight, + 'maxHeight', + equals(10.0), + ) .having( - (MultiImagePickerOptions options) => - options.imageOptions.imageQuality, - 'imageQuality', - equals(70)), + (MultiImagePickerOptions options) => + options.imageOptions.imageQuality, + 'imageQuality', + equals(70), + ), named: 'options', ), ), @@ -560,20 +644,23 @@ void main() { options: argThat( isInstanceOf() .having( - (MultiImagePickerOptions options) => - options.imageOptions.maxWidth, - 'maxWidth', - equals(10.0)) + (MultiImagePickerOptions options) => + options.imageOptions.maxWidth, + 'maxWidth', + equals(10.0), + ) .having( - (MultiImagePickerOptions options) => - options.imageOptions.maxWidth, - 'maxHeight', - equals(10.0)) + (MultiImagePickerOptions options) => + options.imageOptions.maxHeight, + 'maxHeight', + equals(20.0), + ) .having( - (MultiImagePickerOptions options) => - options.imageOptions.imageQuality, - 'imageQuality', - equals(70)), + (MultiImagePickerOptions options) => + options.imageOptions.imageQuality, + 'imageQuality', + equals(70), + ), named: 'options', ), ), @@ -581,22 +668,28 @@ void main() { options: argThat( isInstanceOf() .having( - (MultiImagePickerOptions options) => - options.imageOptions.maxWidth, - 'maxWidth', - equals(10.0)) + (MultiImagePickerOptions options) => + options.imageOptions.maxWidth, + 'maxWidth', + equals(10.0), + ) .having( - (MultiImagePickerOptions options) => - options.imageOptions.maxWidth, - 'maxHeight', - equals(10.0)) + (MultiImagePickerOptions options) => + options.imageOptions.maxHeight, + 'maxHeight', + equals(20.0), + ) .having( - (MultiImagePickerOptions options) => - options.imageOptions.imageQuality, - 'imageQuality', - equals(70)) - .having((MultiImagePickerOptions options) => options.limit, - 'limit', equals(5)), + (MultiImagePickerOptions options) => + options.imageOptions.imageQuality, + 'imageQuality', + equals(70), + ) + .having( + (MultiImagePickerOptions options) => options.limit, + 'limit', + equals(5), + ), named: 'options', ), ), @@ -618,20 +711,11 @@ void main() { test('does not accept a limit argument lower than 2', () { final ImagePicker picker = ImagePicker(); - expect( - () => picker.pickMultiImage(limit: -1), - throwsArgumentError, - ); + expect(() => picker.pickMultiImage(limit: -1), throwsArgumentError); - expect( - () => picker.pickMultiImage(limit: 0), - throwsArgumentError, - ); + expect(() => picker.pickMultiImage(limit: 0), throwsArgumentError); - expect( - () => picker.pickMultiImage(limit: 1), - throwsArgumentError, - ); + expect(() => picker.pickMultiImage(limit: 1), throwsArgumentError); }); test('handles an empty image file response gracefully', () async { @@ -645,34 +729,38 @@ void main() { final ImagePicker picker = ImagePicker(); await picker.pickMultiImage(); - verify(mockPlatform.getMultiImageWithOptions( - options: argThat( - isInstanceOf().having( + verify( + mockPlatform.getMultiImageWithOptions( + options: argThat( + isInstanceOf().having( (MultiImagePickerOptions options) => options.imageOptions.requestFullMetadata, 'requestFullMetadata', - isTrue), - named: 'options', + isTrue, + ), + named: 'options', + ), ), - )); + ); }); test('passes the full metadata argument correctly', () async { final ImagePicker picker = ImagePicker(); - await picker.pickMultiImage( - requestFullMetadata: false, - ); + await picker.pickMultiImage(requestFullMetadata: false); - verify(mockPlatform.getMultiImageWithOptions( - options: argThat( - isInstanceOf().having( + verify( + mockPlatform.getMultiImageWithOptions( + options: argThat( + isInstanceOf().having( (MultiImagePickerOptions options) => options.imageOptions.requestFullMetadata, 'requestFullMetadata', - isFalse), - named: 'options', + isFalse, + ), + named: 'options', + ), ), - )); + ); }); }); }); @@ -680,9 +768,7 @@ void main() { group('#Media', () { setUp(() { when( - mockPlatform.getMedia( - options: anyNamed('options'), - ), + mockPlatform.getMedia(options: anyNamed('options')), ).thenAnswer((Invocation _) async => []); }); @@ -690,24 +776,11 @@ void main() { test('passes the width and height arguments correctly', () async { final ImagePicker picker = ImagePicker(); await picker.pickMedia(); - await picker.pickMedia( - maxWidth: 10.0, - ); - await picker.pickMedia( - maxHeight: 10.0, - ); - await picker.pickMedia( - maxWidth: 10.0, - maxHeight: 20.0, - ); - await picker.pickMedia( - maxWidth: 10.0, - imageQuality: 70, - ); - await picker.pickMedia( - maxHeight: 10.0, - imageQuality: 70, - ); + await picker.pickMedia(maxWidth: 10.0); + await picker.pickMedia(maxHeight: 10.0); + await picker.pickMedia(maxWidth: 10.0, maxHeight: 20.0); + await picker.pickMedia(maxWidth: 10.0, imageQuality: 70); + await picker.pickMedia(maxHeight: 10.0, imageQuality: 70); await picker.pickMedia( maxWidth: 10.0, maxHeight: 20.0, @@ -721,26 +794,25 @@ void main() { verifyInOrder([ mockPlatform.getMedia( - options: argThat( - isInstanceOf(), - named: 'options', - ), + options: argThat(isInstanceOf(), named: 'options'), ), mockPlatform.getMedia( options: argThat( isInstanceOf().having( - (MediaOptions options) => options.imageOptions.maxWidth, - 'maxWidth', - equals(10.0)), + (MediaOptions options) => options.imageOptions.maxWidth, + 'maxWidth', + equals(10.0), + ), named: 'options', ), ), mockPlatform.getMedia( options: argThat( isInstanceOf().having( - (MediaOptions options) => options.imageOptions.maxHeight, - 'maxHeight', - equals(10.0)), + (MediaOptions options) => options.imageOptions.maxHeight, + 'maxHeight', + equals(10.0), + ), named: 'options', ), ), @@ -748,14 +820,15 @@ void main() { options: argThat( isInstanceOf() .having( - (MediaOptions options) => options.imageOptions.maxWidth, - 'maxWidth', - equals(10.0)) + (MediaOptions options) => options.imageOptions.maxWidth, + 'maxWidth', + equals(10.0), + ) .having( - (MediaOptions options) => - options.imageOptions.maxHeight, - 'maxHeight', - equals(20.0)), + (MediaOptions options) => options.imageOptions.maxHeight, + 'maxHeight', + equals(20.0), + ), named: 'options', ), ), @@ -763,14 +836,16 @@ void main() { options: argThat( isInstanceOf() .having( - (MediaOptions options) => options.imageOptions.maxWidth, - 'maxWidth', - equals(10.0)) + (MediaOptions options) => options.imageOptions.maxWidth, + 'maxWidth', + equals(10.0), + ) .having( - (MediaOptions options) => - options.imageOptions.imageQuality, - 'imageQuality', - equals(70)), + (MediaOptions options) => + options.imageOptions.imageQuality, + 'imageQuality', + equals(70), + ), named: 'options', ), ), @@ -778,15 +853,16 @@ void main() { options: argThat( isInstanceOf() .having( - (MediaOptions options) => - options.imageOptions.maxHeight, - 'maxHeight', - equals(10.0)) + (MediaOptions options) => options.imageOptions.maxHeight, + 'maxHeight', + equals(10.0), + ) .having( - (MediaOptions options) => - options.imageOptions.imageQuality, - 'imageQuality', - equals(70)), + (MediaOptions options) => + options.imageOptions.imageQuality, + 'imageQuality', + equals(70), + ), named: 'options', ), ), @@ -794,18 +870,21 @@ void main() { options: argThat( isInstanceOf() .having( - (MediaOptions options) => options.imageOptions.maxWidth, - 'maxWidth', - equals(10.0)) + (MediaOptions options) => options.imageOptions.maxWidth, + 'maxWidth', + equals(10.0), + ) .having( - (MediaOptions options) => options.imageOptions.maxWidth, - 'maxHeight', - equals(10.0)) + (MediaOptions options) => options.imageOptions.maxWidth, + 'maxHeight', + equals(10.0), + ) .having( - (MediaOptions options) => - options.imageOptions.imageQuality, - 'imageQuality', - equals(70)), + (MediaOptions options) => + options.imageOptions.imageQuality, + 'imageQuality', + equals(70), + ), named: 'options', ), ), @@ -814,15 +893,9 @@ void main() { test('does not accept a negative width or height argument', () { final ImagePicker picker = ImagePicker(); - expect( - () => picker.pickMedia(maxWidth: -1.0), - throwsArgumentError, - ); + expect(() => picker.pickMedia(maxWidth: -1.0), throwsArgumentError); - expect( - () => picker.pickMedia(maxHeight: -1.0), - throwsArgumentError, - ); + expect(() => picker.pickMedia(maxHeight: -1.0), throwsArgumentError); }); test('handles an empty image file response gracefully', () async { @@ -836,34 +909,38 @@ void main() { final ImagePicker picker = ImagePicker(); await picker.pickMedia(); - verify(mockPlatform.getMedia( - options: argThat( - isInstanceOf().having( + verify( + mockPlatform.getMedia( + options: argThat( + isInstanceOf().having( (MediaOptions options) => options.imageOptions.requestFullMetadata, 'requestFullMetadata', - isTrue), - named: 'options', + isTrue, + ), + named: 'options', + ), ), - )); + ); }); test('passes the full metadata argument correctly', () async { final ImagePicker picker = ImagePicker(); - await picker.pickMedia( - requestFullMetadata: false, - ); + await picker.pickMedia(requestFullMetadata: false); - verify(mockPlatform.getMedia( - options: argThat( - isInstanceOf().having( + verify( + mockPlatform.getMedia( + options: argThat( + isInstanceOf().having( (MediaOptions options) => options.imageOptions.requestFullMetadata, 'requestFullMetadata', - isFalse), - named: 'options', + isFalse, + ), + named: 'options', + ), ), - )); + ); }); }); @@ -871,24 +948,11 @@ void main() { test('passes the width and height arguments correctly', () async { final ImagePicker picker = ImagePicker(); await picker.pickMultipleMedia(); - await picker.pickMultipleMedia( - maxWidth: 10.0, - ); - await picker.pickMultipleMedia( - maxHeight: 10.0, - ); - await picker.pickMultipleMedia( - maxWidth: 10.0, - maxHeight: 20.0, - ); - await picker.pickMultipleMedia( - maxWidth: 10.0, - imageQuality: 70, - ); - await picker.pickMultipleMedia( - maxHeight: 10.0, - imageQuality: 70, - ); + await picker.pickMultipleMedia(maxWidth: 10.0); + await picker.pickMultipleMedia(maxHeight: 10.0); + await picker.pickMultipleMedia(maxWidth: 10.0, maxHeight: 20.0); + await picker.pickMultipleMedia(maxWidth: 10.0, imageQuality: 70); + await picker.pickMultipleMedia(maxHeight: 10.0, imageQuality: 70); await picker.pickMultipleMedia( maxWidth: 10.0, maxHeight: 20.0, @@ -903,26 +967,25 @@ void main() { verifyInOrder([ mockPlatform.getMedia( - options: argThat( - isInstanceOf(), - named: 'options', - ), + options: argThat(isInstanceOf(), named: 'options'), ), mockPlatform.getMedia( options: argThat( isInstanceOf().having( - (MediaOptions options) => options.imageOptions.maxWidth, - 'maxWidth', - equals(10.0)), + (MediaOptions options) => options.imageOptions.maxWidth, + 'maxWidth', + equals(10.0), + ), named: 'options', ), ), mockPlatform.getMedia( options: argThat( isInstanceOf().having( - (MediaOptions options) => options.imageOptions.maxHeight, - 'maxHeight', - equals(10.0)), + (MediaOptions options) => options.imageOptions.maxHeight, + 'maxHeight', + equals(10.0), + ), named: 'options', ), ), @@ -930,14 +993,15 @@ void main() { options: argThat( isInstanceOf() .having( - (MediaOptions options) => options.imageOptions.maxWidth, - 'maxWidth', - equals(10.0)) + (MediaOptions options) => options.imageOptions.maxWidth, + 'maxWidth', + equals(10.0), + ) .having( - (MediaOptions options) => - options.imageOptions.maxHeight, - 'maxHeight', - equals(20.0)), + (MediaOptions options) => options.imageOptions.maxHeight, + 'maxHeight', + equals(20.0), + ), named: 'options', ), ), @@ -945,14 +1009,16 @@ void main() { options: argThat( isInstanceOf() .having( - (MediaOptions options) => options.imageOptions.maxWidth, - 'maxWidth', - equals(10.0)) + (MediaOptions options) => options.imageOptions.maxWidth, + 'maxWidth', + equals(10.0), + ) .having( - (MediaOptions options) => - options.imageOptions.imageQuality, - 'imageQuality', - equals(70)), + (MediaOptions options) => + options.imageOptions.imageQuality, + 'imageQuality', + equals(70), + ), named: 'options', ), ), @@ -960,15 +1026,16 @@ void main() { options: argThat( isInstanceOf() .having( - (MediaOptions options) => - options.imageOptions.maxHeight, - 'maxHeight', - equals(10.0)) + (MediaOptions options) => options.imageOptions.maxHeight, + 'maxHeight', + equals(10.0), + ) .having( - (MediaOptions options) => - options.imageOptions.imageQuality, - 'imageQuality', - equals(70)), + (MediaOptions options) => + options.imageOptions.imageQuality, + 'imageQuality', + equals(70), + ), named: 'options', ), ), @@ -976,18 +1043,21 @@ void main() { options: argThat( isInstanceOf() .having( - (MediaOptions options) => options.imageOptions.maxWidth, - 'maxWidth', - equals(10.0)) + (MediaOptions options) => options.imageOptions.maxWidth, + 'maxWidth', + equals(10.0), + ) .having( - (MediaOptions options) => options.imageOptions.maxWidth, - 'maxHeight', - equals(10.0)) + (MediaOptions options) => options.imageOptions.maxWidth, + 'maxHeight', + equals(10.0), + ) .having( - (MediaOptions options) => - options.imageOptions.imageQuality, - 'imageQuality', - equals(70)), + (MediaOptions options) => + options.imageOptions.imageQuality, + 'imageQuality', + equals(70), + ), named: 'options', ), ), @@ -995,20 +1065,26 @@ void main() { options: argThat( isInstanceOf() .having( - (MediaOptions options) => options.imageOptions.maxWidth, - 'maxWidth', - equals(10.0)) + (MediaOptions options) => options.imageOptions.maxWidth, + 'maxWidth', + equals(10.0), + ) + .having( + (MediaOptions options) => options.imageOptions.maxWidth, + 'maxHeight', + equals(10.0), + ) .having( - (MediaOptions options) => options.imageOptions.maxWidth, - 'maxHeight', - equals(10.0)) + (MediaOptions options) => + options.imageOptions.imageQuality, + 'imageQuality', + equals(70), + ) .having( - (MediaOptions options) => - options.imageOptions.imageQuality, - 'imageQuality', - equals(70)) - .having((MediaOptions options) => options.limit, 'limit', - equals(5)), + (MediaOptions options) => options.limit, + 'limit', + equals(5), + ), named: 'options', ), ), @@ -1035,15 +1111,9 @@ void main() { throwsArgumentError, ); - expect( - () => picker.pickMultipleMedia(limit: 0), - throwsArgumentError, - ); + expect(() => picker.pickMultipleMedia(limit: 0), throwsArgumentError); - expect( - () => picker.pickMultipleMedia(limit: 1), - throwsArgumentError, - ); + expect(() => picker.pickMultipleMedia(limit: 1), throwsArgumentError); }); test('handles an empty image file response gracefully', () async { @@ -1057,34 +1127,38 @@ void main() { final ImagePicker picker = ImagePicker(); await picker.pickMultipleMedia(); - verify(mockPlatform.getMedia( - options: argThat( - isInstanceOf().having( + verify( + mockPlatform.getMedia( + options: argThat( + isInstanceOf().having( (MediaOptions options) => options.imageOptions.requestFullMetadata, 'requestFullMetadata', - isTrue), - named: 'options', + isTrue, + ), + named: 'options', + ), ), - )); + ); }); test('passes the full metadata argument correctly', () async { final ImagePicker picker = ImagePicker(); - await picker.pickMultipleMedia( - requestFullMetadata: false, - ); + await picker.pickMultipleMedia(requestFullMetadata: false); - verify(mockPlatform.getMedia( - options: argThat( - isInstanceOf().having( + verify( + mockPlatform.getMedia( + options: argThat( + isInstanceOf().having( (MediaOptions options) => options.imageOptions.requestFullMetadata, 'requestFullMetadata', - isFalse), - named: 'options', + isFalse, + ), + named: 'options', + ), ), - )); + ); }); }); test('supportsImageSource calls through to platform', () async { diff --git a/packages/image_picker/image_picker/test/image_picker_test.mocks.dart b/packages/image_picker/image_picker/test/image_picker_test.mocks.dart index 4277592f06b..6aaca18fcac 100644 --- a/packages/image_picker/image_picker/test/image_picker_test.mocks.dart +++ b/packages/image_picker/image_picker/test/image_picker_test.mocks.dart @@ -26,24 +26,14 @@ import 'package:mockito/mockito.dart' as _i1; // ignore_for_file: subtype_of_sealed_class class _FakeLostData_0 extends _i1.SmartFake implements _i2.LostData { - _FakeLostData_0( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); + _FakeLostData_0(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); } class _FakeLostDataResponse_1 extends _i1.SmartFake implements _i2.LostDataResponse { - _FakeLostDataResponse_1( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); + _FakeLostDataResponse_1(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); } /// A class which mocks [ImagePickerPlatform]. @@ -64,19 +54,16 @@ class MockImagePickerPlatform extends _i1.Mock _i2.CameraDevice? preferredCameraDevice = _i2.CameraDevice.rear, }) => (super.noSuchMethod( - Invocation.method( - #pickImage, - [], - { - #source: source, - #maxWidth: maxWidth, - #maxHeight: maxHeight, - #imageQuality: imageQuality, - #preferredCameraDevice: preferredCameraDevice, - }, - ), - returnValue: _i4.Future<_i2.PickedFile?>.value(), - ) as _i4.Future<_i2.PickedFile?>); + Invocation.method(#pickImage, [], { + #source: source, + #maxWidth: maxWidth, + #maxHeight: maxHeight, + #imageQuality: imageQuality, + #preferredCameraDevice: preferredCameraDevice, + }), + returnValue: _i4.Future<_i2.PickedFile?>.value(), + ) + as _i4.Future<_i2.PickedFile?>); @override _i4.Future?> pickMultiImage({ @@ -85,17 +72,14 @@ class MockImagePickerPlatform extends _i1.Mock int? imageQuality, }) => (super.noSuchMethod( - Invocation.method( - #pickMultiImage, - [], - { - #maxWidth: maxWidth, - #maxHeight: maxHeight, - #imageQuality: imageQuality, - }, - ), - returnValue: _i4.Future?>.value(), - ) as _i4.Future?>); + Invocation.method(#pickMultiImage, [], { + #maxWidth: maxWidth, + #maxHeight: maxHeight, + #imageQuality: imageQuality, + }), + returnValue: _i4.Future?>.value(), + ) + as _i4.Future?>); @override _i4.Future<_i2.PickedFile?> pickVideo({ @@ -104,32 +88,24 @@ class MockImagePickerPlatform extends _i1.Mock Duration? maxDuration, }) => (super.noSuchMethod( - Invocation.method( - #pickVideo, - [], - { - #source: source, - #preferredCameraDevice: preferredCameraDevice, - #maxDuration: maxDuration, - }, - ), - returnValue: _i4.Future<_i2.PickedFile?>.value(), - ) as _i4.Future<_i2.PickedFile?>); + Invocation.method(#pickVideo, [], { + #source: source, + #preferredCameraDevice: preferredCameraDevice, + #maxDuration: maxDuration, + }), + returnValue: _i4.Future<_i2.PickedFile?>.value(), + ) + as _i4.Future<_i2.PickedFile?>); @override - _i4.Future<_i2.LostData> retrieveLostData() => (super.noSuchMethod( - Invocation.method( - #retrieveLostData, - [], - ), - returnValue: _i4.Future<_i2.LostData>.value(_FakeLostData_0( - this, - Invocation.method( - #retrieveLostData, - [], - ), - )), - ) as _i4.Future<_i2.LostData>); + _i4.Future<_i2.LostData> retrieveLostData() => + (super.noSuchMethod( + Invocation.method(#retrieveLostData, []), + returnValue: _i4.Future<_i2.LostData>.value( + _FakeLostData_0(this, Invocation.method(#retrieveLostData, [])), + ), + ) + as _i4.Future<_i2.LostData>); @override _i4.Future<_i5.XFile?> getImage({ @@ -140,19 +116,16 @@ class MockImagePickerPlatform extends _i1.Mock _i2.CameraDevice? preferredCameraDevice = _i2.CameraDevice.rear, }) => (super.noSuchMethod( - Invocation.method( - #getImage, - [], - { - #source: source, - #maxWidth: maxWidth, - #maxHeight: maxHeight, - #imageQuality: imageQuality, - #preferredCameraDevice: preferredCameraDevice, - }, - ), - returnValue: _i4.Future<_i5.XFile?>.value(), - ) as _i4.Future<_i5.XFile?>); + Invocation.method(#getImage, [], { + #source: source, + #maxWidth: maxWidth, + #maxHeight: maxHeight, + #imageQuality: imageQuality, + #preferredCameraDevice: preferredCameraDevice, + }), + returnValue: _i4.Future<_i5.XFile?>.value(), + ) + as _i4.Future<_i5.XFile?>); @override _i4.Future?> getMultiImage({ @@ -161,28 +134,22 @@ class MockImagePickerPlatform extends _i1.Mock int? imageQuality, }) => (super.noSuchMethod( - Invocation.method( - #getMultiImage, - [], - { - #maxWidth: maxWidth, - #maxHeight: maxHeight, - #imageQuality: imageQuality, - }, - ), - returnValue: _i4.Future?>.value(), - ) as _i4.Future?>); + Invocation.method(#getMultiImage, [], { + #maxWidth: maxWidth, + #maxHeight: maxHeight, + #imageQuality: imageQuality, + }), + returnValue: _i4.Future?>.value(), + ) + as _i4.Future?>); @override _i4.Future> getMedia({required _i2.MediaOptions? options}) => (super.noSuchMethod( - Invocation.method( - #getMedia, - [], - {#options: options}, - ), - returnValue: _i4.Future>.value(<_i5.XFile>[]), - ) as _i4.Future>); + Invocation.method(#getMedia, [], {#options: options}), + returnValue: _i4.Future>.value(<_i5.XFile>[]), + ) + as _i4.Future>); @override _i4.Future<_i5.XFile?> getVideo({ @@ -191,33 +158,27 @@ class MockImagePickerPlatform extends _i1.Mock Duration? maxDuration, }) => (super.noSuchMethod( - Invocation.method( - #getVideo, - [], - { - #source: source, - #preferredCameraDevice: preferredCameraDevice, - #maxDuration: maxDuration, - }, - ), - returnValue: _i4.Future<_i5.XFile?>.value(), - ) as _i4.Future<_i5.XFile?>); + Invocation.method(#getVideo, [], { + #source: source, + #preferredCameraDevice: preferredCameraDevice, + #maxDuration: maxDuration, + }), + returnValue: _i4.Future<_i5.XFile?>.value(), + ) + as _i4.Future<_i5.XFile?>); @override - _i4.Future<_i2.LostDataResponse> getLostData() => (super.noSuchMethod( - Invocation.method( - #getLostData, - [], - ), - returnValue: - _i4.Future<_i2.LostDataResponse>.value(_FakeLostDataResponse_1( - this, - Invocation.method( - #getLostData, - [], - ), - )), - ) as _i4.Future<_i2.LostDataResponse>); + _i4.Future<_i2.LostDataResponse> getLostData() => + (super.noSuchMethod( + Invocation.method(#getLostData, []), + returnValue: _i4.Future<_i2.LostDataResponse>.value( + _FakeLostDataResponse_1( + this, + Invocation.method(#getLostData, []), + ), + ), + ) + as _i4.Future<_i2.LostDataResponse>); @override _i4.Future<_i5.XFile?> getImageFromSource({ @@ -225,49 +186,43 @@ class MockImagePickerPlatform extends _i1.Mock _i2.ImagePickerOptions? options = const _i2.ImagePickerOptions(), }) => (super.noSuchMethod( - Invocation.method( - #getImageFromSource, - [], - { - #source: source, - #options: options, - }, - ), - returnValue: _i4.Future<_i5.XFile?>.value(), - ) as _i4.Future<_i5.XFile?>); + Invocation.method(#getImageFromSource, [], { + #source: source, + #options: options, + }), + returnValue: _i4.Future<_i5.XFile?>.value(), + ) + as _i4.Future<_i5.XFile?>); @override - _i4.Future> getMultiImageWithOptions( - {_i2.MultiImagePickerOptions? options = - const _i2.MultiImagePickerOptions()}) => + _i4.Future> getMultiImageWithOptions({ + _i2.MultiImagePickerOptions? options = const _i2.MultiImagePickerOptions(), + }) => (super.noSuchMethod( - Invocation.method( - #getMultiImageWithOptions, - [], - {#options: options}, - ), - returnValue: _i4.Future>.value(<_i5.XFile>[]), - ) as _i4.Future>); + Invocation.method(#getMultiImageWithOptions, [], { + #options: options, + }), + returnValue: _i4.Future>.value(<_i5.XFile>[]), + ) + as _i4.Future>); @override - _i4.Future> getMultiVideoWithOptions( - {_i2.MultiVideoPickerOptions? options = - const _i2.MultiVideoPickerOptions()}) => + _i4.Future> getMultiVideoWithOptions({ + _i2.MultiVideoPickerOptions? options = const _i2.MultiVideoPickerOptions(), + }) => (super.noSuchMethod( - Invocation.method( - #getMultiVideoWithOptions, - [], - {#options: options}, - ), - returnValue: _i4.Future>.value(<_i5.XFile>[]), - ) as _i4.Future>); + Invocation.method(#getMultiVideoWithOptions, [], { + #options: options, + }), + returnValue: _i4.Future>.value(<_i5.XFile>[]), + ) + as _i4.Future>); @override - bool supportsImageSource(_i2.ImageSource? source) => (super.noSuchMethod( - Invocation.method( - #supportsImageSource, - [source], - ), - returnValue: false, - ) as bool); + bool supportsImageSource(_i2.ImageSource? source) => + (super.noSuchMethod( + Invocation.method(#supportsImageSource, [source]), + returnValue: false, + ) + as bool); } diff --git a/packages/image_picker/image_picker_android/CHANGELOG.md b/packages/image_picker/image_picker_android/CHANGELOG.md index ac27246ea3a..6bf6715bf77 100644 --- a/packages/image_picker/image_picker_android/CHANGELOG.md +++ b/packages/image_picker/image_picker_android/CHANGELOG.md @@ -1,3 +1,7 @@ +## NEXT + +* Updates minimum supported SDK version to Flutter 3.29/Dart 3.7. + ## 0.8.13 * Adds support for `getMultiVideoWithOptions`. diff --git a/packages/image_picker/image_picker_android/example/lib/main.dart b/packages/image_picker/image_picker_android/example/lib/main.dart index dea02fa2320..6e7b2875aba 100755 --- a/packages/image_picker/image_picker_android/example/lib/main.dart +++ b/packages/image_picker/image_picker_android/example/lib/main.dart @@ -79,8 +79,9 @@ class _MyHomePageState extends State { Future _playVideo(XFile? file) async { if (file != null && mounted) { await _disposeVideoController(); - final VideoPlayerController controller = - VideoPlayerController.file(File(file.path)); + final VideoPlayerController controller = VideoPlayerController.file( + File(file.path), + ); _controller = controller; await controller.setVolume(1.0); await controller.initialize(); @@ -106,7 +107,9 @@ class _MyHomePageState extends State { files = await _picker.getMultiVideoWithOptions(); } else { final XFile? file = await _picker.getVideo( - source: source, maxDuration: const Duration(seconds: 10)); + source: source, + maxDuration: const Duration(seconds: 10), + ); files = [if (file != null) file]; } if (files.isNotEmpty && context.mounted) { @@ -115,28 +118,33 @@ class _MyHomePageState extends State { await _playVideo(files.first); } } else if (allowMultiple) { - await _displayPickImageDialog(context, true, (double? maxWidth, - double? maxHeight, int? quality, int? limit) async { + await _displayPickImageDialog(context, true, ( + double? maxWidth, + double? maxHeight, + int? quality, + int? limit, + ) async { try { final ImageOptions imageOptions = ImageOptions( maxWidth: maxWidth, maxHeight: maxHeight, imageQuality: quality, ); - final List pickedFileList = isMedia - ? await _picker.getMedia( - options: MediaOptions( - allowMultiple: allowMultiple, - imageOptions: imageOptions, - limit: limit, - ), - ) - : await _picker.getMultiImageWithOptions( - options: MultiImagePickerOptions( - imageOptions: imageOptions, - limit: limit, - ), - ); + final List pickedFileList = + isMedia + ? await _picker.getMedia( + options: MediaOptions( + allowMultiple: allowMultiple, + imageOptions: imageOptions, + limit: limit, + ), + ) + : await _picker.getMultiImageWithOptions( + options: MultiImagePickerOptions( + imageOptions: imageOptions, + limit: limit, + ), + ); if (pickedFileList.isNotEmpty && context.mounted) { _showPickedSnackBar(context, pickedFileList); } @@ -150,19 +158,26 @@ class _MyHomePageState extends State { } }); } else if (isMedia) { - await _displayPickImageDialog(context, false, (double? maxWidth, - double? maxHeight, int? quality, int? limit) async { + await _displayPickImageDialog(context, false, ( + double? maxWidth, + double? maxHeight, + int? quality, + int? limit, + ) async { try { final List pickedFileList = []; - final XFile? media = _firstOrNull(await _picker.getMedia( - options: MediaOptions( + final XFile? media = _firstOrNull( + await _picker.getMedia( + options: MediaOptions( allowMultiple: allowMultiple, imageOptions: ImageOptions( maxWidth: maxWidth, maxHeight: maxHeight, imageQuality: quality, - )), - )); + ), + ), + ), + ); if (media != null) { pickedFileList.add(media); @@ -175,8 +190,12 @@ class _MyHomePageState extends State { } }); } else { - await _displayPickImageDialog(context, false, (double? maxWidth, - double? maxHeight, int? quality, int? limit) async { + await _displayPickImageDialog(context, false, ( + double? maxWidth, + double? maxHeight, + int? quality, + int? limit, + ) async { try { final XFile? pickedFile = await _picker.getImageFromSource( source: source, @@ -257,21 +276,27 @@ class _MyHomePageState extends State { return Column( mainAxisSize: MainAxisSize.min, children: [ - Text(image.name, - key: const Key('image_picker_example_picked_image_name')), + Text( + image.name, + key: const Key('image_picker_example_picked_image_name'), + ), Semantics( label: 'image_picker_example_picked_image', - child: mime == null || mime.startsWith('image/') - ? Image.file( - File(_mediaFileList![index].path), - errorBuilder: (BuildContext context, Object error, - StackTrace? stackTrace) { - return const Center( - child: - Text('This image type is not supported')); - }, - ) - : _buildInlineVideoPlayer(index), + child: + mime == null || mime.startsWith('image/') + ? Image.file( + File(_mediaFileList![index].path), + errorBuilder: ( + BuildContext context, + Object error, + StackTrace? stackTrace, + ) { + return const Center( + child: Text('This image type is not supported'), + ); + }, + ) + : _buildInlineVideoPlayer(index), ), ], ); @@ -293,8 +318,9 @@ class _MyHomePageState extends State { } Widget _buildInlineVideoPlayer(int index) { - final VideoPlayerController controller = - VideoPlayerController.file(File(_mediaFileList![index].path)); + final VideoPlayerController controller = VideoPlayerController.file( + File(_mediaFileList![index].path), + ); controller.setVolume(1.0); controller.initialize(); controller.setLooping(true); @@ -337,40 +363,42 @@ class _MyHomePageState extends State { @override Widget build(BuildContext context) { return Scaffold( - appBar: AppBar( - title: Text(widget.title!), - ), + appBar: AppBar(title: Text(widget.title!)), body: Align( alignment: Alignment.topCenter, - child: !kIsWeb && defaultTargetPlatform == TargetPlatform.android - ? FutureBuilder( - future: retrieveLostData(), - builder: (BuildContext context, AsyncSnapshot snapshot) { - switch (snapshot.connectionState) { - case ConnectionState.none: - case ConnectionState.waiting: - return const Text( - 'You have not yet picked an image.', - textAlign: TextAlign.center, - ); - case ConnectionState.done: - return _handlePreview(); - case ConnectionState.active: - if (snapshot.hasError) { - return Text( - 'Pick image/video error: ${snapshot.error}}', - textAlign: TextAlign.center, - ); - } else { + child: + !kIsWeb && defaultTargetPlatform == TargetPlatform.android + ? FutureBuilder( + future: retrieveLostData(), + builder: ( + BuildContext context, + AsyncSnapshot snapshot, + ) { + switch (snapshot.connectionState) { + case ConnectionState.none: + case ConnectionState.waiting: return const Text( 'You have not yet picked an image.', textAlign: TextAlign.center, ); - } - } - }, - ) - : _handlePreview(), + case ConnectionState.done: + return _handlePreview(); + case ConnectionState.active: + if (snapshot.hasError) { + return Text( + 'Pick image/video error: ${snapshot.error}}', + textAlign: TextAlign.center, + ); + } else { + return const Text( + 'You have not yet picked an image.', + textAlign: TextAlign.center, + ); + } + } + }, + ) + : _handlePreview(), ), floatingActionButton: Column( mainAxisAlignment: MainAxisAlignment.end, @@ -474,8 +502,11 @@ class _MyHomePageState extends State { backgroundColor: Colors.red, onPressed: () { _isVideo = true; - _onImageButtonPressed(ImageSource.gallery, - context: context, allowMultiple: true); + _onImageButtonPressed( + ImageSource.gallery, + context: context, + allowMultiple: true, + ); }, heroTag: 'multiVideo', tooltip: 'Pick multiple videos', @@ -512,83 +543,105 @@ class _MyHomePageState extends State { } Future _displayPickImageDialog( - BuildContext context, bool isMulti, OnPickImageCallback onPick) async { + BuildContext context, + bool isMulti, + OnPickImageCallback onPick, + ) async { return showDialog( - context: context, - builder: (BuildContext context) { - return AlertDialog( - title: const Text('Add optional parameters'), - content: Column( - children: [ - TextField( - controller: maxWidthController, - keyboardType: - const TextInputType.numberWithOptions(decimal: true), - decoration: const InputDecoration( - hintText: 'Enter maxWidth if desired'), + context: context, + builder: (BuildContext context) { + return AlertDialog( + title: const Text('Add optional parameters'), + content: Column( + children: [ + TextField( + controller: maxWidthController, + keyboardType: const TextInputType.numberWithOptions( + decimal: true, ), - TextField( - controller: maxHeightController, - keyboardType: - const TextInputType.numberWithOptions(decimal: true), - decoration: const InputDecoration( - hintText: 'Enter maxHeight if desired'), + decoration: const InputDecoration( + hintText: 'Enter maxWidth if desired', + ), + ), + TextField( + controller: maxHeightController, + keyboardType: const TextInputType.numberWithOptions( + decimal: true, ), + decoration: const InputDecoration( + hintText: 'Enter maxHeight if desired', + ), + ), + TextField( + controller: qualityController, + keyboardType: TextInputType.number, + decoration: const InputDecoration( + hintText: 'Enter quality if desired', + ), + ), + if (isMulti) TextField( - controller: qualityController, + controller: limitController, keyboardType: TextInputType.number, decoration: const InputDecoration( - hintText: 'Enter quality if desired'), - ), - if (isMulti) - TextField( - controller: limitController, - keyboardType: TextInputType.number, - decoration: const InputDecoration( - hintText: 'Enter limit if desired'), + hintText: 'Enter limit if desired', ), - ], + ), + ], + ), + actions: [ + TextButton( + child: const Text('CANCEL'), + onPressed: () { + Navigator.of(context).pop(); + }, ), - actions: [ - TextButton( - child: const Text('CANCEL'), - onPressed: () { - Navigator.of(context).pop(); - }, - ), - TextButton( - child: const Text('PICK'), - onPressed: () { - final double? width = maxWidthController.text.isNotEmpty + TextButton( + child: const Text('PICK'), + onPressed: () { + final double? width = + maxWidthController.text.isNotEmpty ? double.parse(maxWidthController.text) : null; - final double? height = maxHeightController.text.isNotEmpty + final double? height = + maxHeightController.text.isNotEmpty ? double.parse(maxHeightController.text) : null; - final int? quality = qualityController.text.isNotEmpty + final int? quality = + qualityController.text.isNotEmpty ? int.parse(qualityController.text) : null; - final int? limit = limitController.text.isNotEmpty + final int? limit = + limitController.text.isNotEmpty ? int.parse(limitController.text) : null; - onPick(width, height, quality, limit); - Navigator.of(context).pop(); - }), - ], - ); - }); + onPick(width, height, quality, limit); + Navigator.of(context).pop(); + }, + ), + ], + ); + }, + ); } void _showPickedSnackBar(BuildContext context, List files) { - ScaffoldMessenger.of(context).showSnackBar(SnackBar( - content: Text('Picked: ${files.map((XFile it) => it.name).join(',')}'), - duration: const Duration(seconds: 2), - )); + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text('Picked: ${files.map((XFile it) => it.name).join(',')}'), + duration: const Duration(seconds: 2), + ), + ); } } -typedef OnPickImageCallback = void Function( - double? maxWidth, double? maxHeight, int? quality, int? limit); +typedef OnPickImageCallback = + void Function( + double? maxWidth, + double? maxHeight, + int? quality, + int? limit, + ); class AspectRatioVideo extends StatefulWidget { const AspectRatioVideo(this.controller, {super.key}); diff --git a/packages/image_picker/image_picker_android/example/pubspec.yaml b/packages/image_picker/image_picker_android/example/pubspec.yaml index 9df61214efc..2e950379b87 100644 --- a/packages/image_picker/image_picker_android/example/pubspec.yaml +++ b/packages/image_picker/image_picker_android/example/pubspec.yaml @@ -3,8 +3,8 @@ description: Demonstrates how to use the image_picker plugin. publish_to: none environment: - sdk: ^3.6.0 - flutter: ">=3.27.0" + sdk: ^3.7.0 + flutter: ">=3.29.0" dependencies: flutter: diff --git a/packages/image_picker/image_picker_android/lib/image_picker_android.dart b/packages/image_picker/image_picker_android/lib/image_picker_android.dart index 1e19561e7d5..32c7a6e4b33 100644 --- a/packages/image_picker/image_picker_android/lib/image_picker_android.dart +++ b/packages/image_picker/image_picker_android/lib/image_picker_android.dart @@ -13,7 +13,7 @@ import 'src/messages.g.dart'; class ImagePickerAndroid extends ImagePickerPlatform { /// Creates a new plugin implementation instance. ImagePickerAndroid({@visibleForTesting ImagePickerApi? api}) - : _hostApi = api ?? ImagePickerApi(); + : _hostApi = api ?? ImagePickerApi(); final ImagePickerApi _hostApi; @@ -71,7 +71,10 @@ class ImagePickerAndroid extends ImagePickerPlatform { }) { if (imageQuality != null && (imageQuality < 0 || imageQuality > 100)) { throw ArgumentError.value( - imageQuality, 'imageQuality', 'must be between 0 and 100'); + imageQuality, + 'imageQuality', + 'must be between 0 and 100', + ); } if (maxWidth != null && maxWidth < 0) { @@ -89,9 +92,10 @@ class ImagePickerAndroid extends ImagePickerPlatform { return _hostApi.pickImages( SourceSpecification(type: SourceType.gallery), ImageSelectionOptions( - maxWidth: maxWidth, - maxHeight: maxHeight, - quality: imageQuality ?? 100), + maxWidth: maxWidth, + maxHeight: maxHeight, + quality: imageQuality ?? 100, + ), GeneralOptions( allowMultiple: true, usePhotoPicker: useAndroidPhotoPicker, @@ -110,7 +114,10 @@ class ImagePickerAndroid extends ImagePickerPlatform { }) async { if (imageQuality != null && (imageQuality < 0 || imageQuality > 100)) { throw ArgumentError.value( - imageQuality, 'imageQuality', 'must be between 0 and 100'); + imageQuality, + 'imageQuality', + 'must be between 0 and 100', + ); } if (maxWidth != null && maxWidth < 0) { @@ -124,9 +131,10 @@ class ImagePickerAndroid extends ImagePickerPlatform { final List paths = await _hostApi.pickImages( _buildSourceSpec(source, preferredCameraDevice), ImageSelectionOptions( - maxWidth: maxWidth, - maxHeight: maxHeight, - quality: imageQuality ?? 100), + maxWidth: maxWidth, + maxHeight: maxHeight, + quality: imageQuality ?? 100, + ), GeneralOptions( allowMultiple: false, usePhotoPicker: useAndroidPhotoPicker, @@ -236,15 +244,11 @@ class ImagePickerAndroid extends ImagePickerPlatform { } @override - Future> getMedia({ - required MediaOptions options, - }) async { + Future> getMedia({required MediaOptions options}) async { return (await _hostApi.pickMedia( _mediaOptionsToMediaSelectionOptions(options), _mediaOptionsToGeneralOptions(options), - )) - .map((String? path) => XFile(path!)) - .toList(); + )).map((String? path) => XFile(path!)).toList(); } @override @@ -283,25 +287,29 @@ class ImagePickerAndroid extends ImagePickerPlatform { } MediaSelectionOptions _mediaOptionsToMediaSelectionOptions( - MediaOptions mediaOptions) { + MediaOptions mediaOptions, + ) { final ImageSelectionOptions imageSelectionOptions = _imageOptionsToImageSelectionOptionsWithValidator( - mediaOptions.imageOptions); + mediaOptions.imageOptions, + ); - return MediaSelectionOptions( - imageSelectionOptions: imageSelectionOptions, - ); + return MediaSelectionOptions(imageSelectionOptions: imageSelectionOptions); } ImageSelectionOptions _imageOptionsToImageSelectionOptionsWithValidator( - ImageOptions? imageOptions) { + ImageOptions? imageOptions, + ) { final double? maxHeight = imageOptions?.maxHeight; final double? maxWidth = imageOptions?.maxWidth; final int? imageQuality = imageOptions?.imageQuality; if (imageQuality != null && (imageQuality < 0 || imageQuality > 100)) { throw ArgumentError.value( - imageQuality, 'imageQuality', 'must be between 0 and 100'); + imageQuality, + 'imageQuality', + 'must be between 0 and 100', + ); } if (maxWidth != null && maxWidth < 0) { @@ -312,7 +320,10 @@ class ImagePickerAndroid extends ImagePickerPlatform { throw ArgumentError.value(maxHeight, 'maxHeight', 'cannot be negative'); } return ImageSelectionOptions( - quality: imageQuality ?? 100, maxHeight: maxHeight, maxWidth: maxWidth); + quality: imageQuality ?? 100, + maxHeight: maxHeight, + maxWidth: maxWidth, + ); } GeneralOptions _mediaOptionsToGeneralOptions(MediaOptions options) { @@ -365,9 +376,10 @@ class ImagePickerAndroid extends ImagePickerPlatform { assert(result.paths.isEmpty != (result.error == null)); final CacheRetrievalError? error = result.error; - final PlatformException? exception = error == null - ? null - : PlatformException(code: error.code, message: error.message); + final PlatformException? exception = + error == null + ? null + : PlatformException(code: error.code, message: error.message); // Entries are guaranteed not to be null, even though that's not currently // expressible in Pigeon. @@ -383,10 +395,13 @@ class ImagePickerAndroid extends ImagePickerPlatform { } SourceSpecification _buildSourceSpec( - ImageSource source, CameraDevice device) { + ImageSource source, + CameraDevice device, + ) { return SourceSpecification( - type: _sourceSpecTypeForSource(source), - camera: _sourceSpecCameraForDevice(device)); + type: _sourceSpecTypeForSource(source), + camera: _sourceSpecCameraForDevice(device), + ); } SourceType _sourceSpecTypeForSource(ImageSource source) { diff --git a/packages/image_picker/image_picker_android/lib/src/messages.g.dart b/packages/image_picker/image_picker_android/lib/src/messages.g.dart index c11b059ee30..5b3313a9bf1 100644 --- a/packages/image_picker/image_picker_android/lib/src/messages.g.dart +++ b/packages/image_picker/image_picker_android/lib/src/messages.g.dart @@ -18,8 +18,11 @@ PlatformException _createConnectionError(String channelName) { ); } -List wrapResponse( - {Object? result, PlatformException? error, bool empty = false}) { +List wrapResponse({ + Object? result, + PlatformException? error, + bool empty = false, +}) { if (empty) { return []; } @@ -29,20 +32,11 @@ List wrapResponse( return [error.code, error.message, error.details]; } -enum SourceCamera { - rear, - front, -} +enum SourceCamera { rear, front } -enum SourceType { - camera, - gallery, -} +enum SourceType { camera, gallery } -enum CacheRetrievalType { - image, - video, -} +enum CacheRetrievalType { image, video } class GeneralOptions { GeneralOptions({ @@ -58,11 +52,7 @@ class GeneralOptions { int? limit; Object encode() { - return [ - allowMultiple, - usePhotoPicker, - limit, - ]; + return [allowMultiple, usePhotoPicker, limit]; } static GeneralOptions decode(Object result) { @@ -77,11 +67,7 @@ class GeneralOptions { /// Options for image selection and output. class ImageSelectionOptions { - ImageSelectionOptions({ - this.maxWidth, - this.maxHeight, - required this.quality, - }); + ImageSelectionOptions({this.maxWidth, this.maxHeight, required this.quality}); /// If set, the max width that the image should be resized to fit in. double? maxWidth; @@ -95,11 +81,7 @@ class ImageSelectionOptions { int quality; Object encode() { - return [ - maxWidth, - maxHeight, - quality, - ]; + return [maxWidth, maxHeight, quality]; } static ImageSelectionOptions decode(Object result) { @@ -113,16 +95,12 @@ class ImageSelectionOptions { } class MediaSelectionOptions { - MediaSelectionOptions({ - required this.imageSelectionOptions, - }); + MediaSelectionOptions({required this.imageSelectionOptions}); ImageSelectionOptions imageSelectionOptions; Object encode() { - return [ - imageSelectionOptions, - ]; + return [imageSelectionOptions]; } static MediaSelectionOptions decode(Object result) { @@ -135,43 +113,31 @@ class MediaSelectionOptions { /// Options for image selection and output. class VideoSelectionOptions { - VideoSelectionOptions({ - this.maxDurationSeconds, - }); + VideoSelectionOptions({this.maxDurationSeconds}); /// The maximum desired length for the video, in seconds. int? maxDurationSeconds; Object encode() { - return [ - maxDurationSeconds, - ]; + return [maxDurationSeconds]; } static VideoSelectionOptions decode(Object result) { result as List; - return VideoSelectionOptions( - maxDurationSeconds: result[0] as int?, - ); + return VideoSelectionOptions(maxDurationSeconds: result[0] as int?); } } /// Specification for the source of an image or video selection. class SourceSpecification { - SourceSpecification({ - required this.type, - this.camera, - }); + SourceSpecification({required this.type, this.camera}); SourceType type; SourceCamera? camera; Object encode() { - return [ - type, - camera, - ]; + return [type, camera]; } static SourceSpecification decode(Object result) { @@ -187,20 +153,14 @@ class SourceSpecification { /// /// The data here maps to the `PlatformException` that will be created from it. class CacheRetrievalError { - CacheRetrievalError({ - required this.code, - this.message, - }); + CacheRetrievalError({required this.code, this.message}); String code; String? message; Object encode() { - return [ - code, - message, - ]; + return [code, message]; } static CacheRetrievalError decode(Object result) { @@ -230,11 +190,7 @@ class CacheRetrievalResult { List paths; Object encode() { - return [ - type, - error, - paths, - ]; + return [type, error, paths]; } static CacheRetrievalResult decode(Object result) { @@ -325,11 +281,12 @@ class ImagePickerApi { /// Constructor for [ImagePickerApi]. The [binaryMessenger] named argument is /// available for dependency injection. If it is left null, the default /// BinaryMessenger will be used which routes to the host platform. - ImagePickerApi( - {BinaryMessenger? binaryMessenger, String messageChannelSuffix = ''}) - : pigeonVar_binaryMessenger = binaryMessenger, - pigeonVar_messageChannelSuffix = - messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; + ImagePickerApi({ + BinaryMessenger? binaryMessenger, + String messageChannelSuffix = '', + }) : pigeonVar_binaryMessenger = binaryMessenger, + pigeonVar_messageChannelSuffix = + messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; final BinaryMessenger? pigeonVar_binaryMessenger; static const MessageCodec pigeonChannelCodec = _PigeonCodec(); @@ -337,18 +294,22 @@ class ImagePickerApi { final String pigeonVar_messageChannelSuffix; /// Selects images and returns their paths. - Future> pickImages(SourceSpecification source, - ImageSelectionOptions options, GeneralOptions generalOptions) async { + Future> pickImages( + SourceSpecification source, + ImageSelectionOptions options, + GeneralOptions generalOptions, + ) async { final String pigeonVar_channelName = 'dev.flutter.pigeon.image_picker_android.ImagePickerApi.pickImages$pigeonVar_messageChannelSuffix'; final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - pigeonVar_channelName, - pigeonChannelCodec, - binaryMessenger: pigeonVar_binaryMessenger, - ); - final List? pigeonVar_replyList = await pigeonVar_channel - .send([source, options, generalOptions]) as List?; + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([source, options, generalOptions]) + as List?; if (pigeonVar_replyList == null) { throw _createConnectionError(pigeonVar_channelName); } else if (pigeonVar_replyList.length > 1) { @@ -368,18 +329,22 @@ class ImagePickerApi { } /// Selects video and returns their paths. - Future> pickVideos(SourceSpecification source, - VideoSelectionOptions options, GeneralOptions generalOptions) async { + Future> pickVideos( + SourceSpecification source, + VideoSelectionOptions options, + GeneralOptions generalOptions, + ) async { final String pigeonVar_channelName = 'dev.flutter.pigeon.image_picker_android.ImagePickerApi.pickVideos$pigeonVar_messageChannelSuffix'; final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - pigeonVar_channelName, - pigeonChannelCodec, - binaryMessenger: pigeonVar_binaryMessenger, - ); - final List? pigeonVar_replyList = await pigeonVar_channel - .send([source, options, generalOptions]) as List?; + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([source, options, generalOptions]) + as List?; if (pigeonVar_replyList == null) { throw _createConnectionError(pigeonVar_channelName); } else if (pigeonVar_replyList.length > 1) { @@ -399,19 +364,24 @@ class ImagePickerApi { } /// Selects images and videos and returns their paths. - Future> pickMedia(MediaSelectionOptions mediaSelectionOptions, - GeneralOptions generalOptions) async { + Future> pickMedia( + MediaSelectionOptions mediaSelectionOptions, + GeneralOptions generalOptions, + ) async { final String pigeonVar_channelName = 'dev.flutter.pigeon.image_picker_android.ImagePickerApi.pickMedia$pigeonVar_messageChannelSuffix'; final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - pigeonVar_channelName, - pigeonChannelCodec, - binaryMessenger: pigeonVar_binaryMessenger, - ); - final List? pigeonVar_replyList = await pigeonVar_channel - .send([mediaSelectionOptions, generalOptions]) - as List?; + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([ + mediaSelectionOptions, + generalOptions, + ]) + as List?; if (pigeonVar_replyList == null) { throw _createConnectionError(pigeonVar_channelName); } else if (pigeonVar_replyList.length > 1) { @@ -436,10 +406,10 @@ class ImagePickerApi { 'dev.flutter.pigeon.image_picker_android.ImagePickerApi.retrieveLostResults$pigeonVar_messageChannelSuffix'; final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - pigeonVar_channelName, - pigeonChannelCodec, - binaryMessenger: pigeonVar_binaryMessenger, - ); + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); final List? pigeonVar_replyList = await pigeonVar_channel.send(null) as List?; if (pigeonVar_replyList == null) { diff --git a/packages/image_picker/image_picker_android/pigeons/messages.dart b/packages/image_picker/image_picker_android/pigeons/messages.dart index 2d124eb12fd..72ad4b183dc 100644 --- a/packages/image_picker/image_picker_android/pigeons/messages.dart +++ b/packages/image_picker/image_picker_android/pigeons/messages.dart @@ -4,15 +4,16 @@ 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', +@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'), + copyrightHeader: 'pigeons/copyright.txt', ), - copyrightHeader: 'pigeons/copyright.txt', -)) +) class GeneralOptions { GeneralOptions(this.allowMultiple, this.usePhotoPicker, this.limit); bool allowMultiple; @@ -37,9 +38,7 @@ class ImageSelectionOptions { } class MediaSelectionOptions { - MediaSelectionOptions({ - required this.imageSelectionOptions, - }); + MediaSelectionOptions({required this.imageSelectionOptions}); ImageSelectionOptions imageSelectionOptions; } @@ -79,8 +78,11 @@ enum CacheRetrievalType { image, video } /// The result of retrieving cached results from a previous run. class CacheRetrievalResult { - CacheRetrievalResult( - {required this.type, this.error, this.paths = const []}); + CacheRetrievalResult({ + required this.type, + this.error, + this.paths = const [], + }); /// The type of the retrieved data. final CacheRetrievalType type; diff --git a/packages/image_picker/image_picker_android/pubspec.yaml b/packages/image_picker/image_picker_android/pubspec.yaml index b6cade1ae3b..d2a1505d064 100755 --- a/packages/image_picker/image_picker_android/pubspec.yaml +++ b/packages/image_picker/image_picker_android/pubspec.yaml @@ -5,8 +5,8 @@ issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+ version: 0.8.13 environment: - sdk: ^3.6.0 - flutter: ">=3.27.0" + sdk: ^3.7.0 + flutter: ">=3.29.0" flutter: plugin: diff --git a/packages/image_picker/image_picker_android/test/image_picker_android_test.dart b/packages/image_picker/image_picker_android/test/image_picker_android_test.dart index b0d84854418..c2a33271dce 100644 --- a/packages/image_picker/image_picker_android/test/image_picker_android_test.dart +++ b/packages/image_picker/image_picker_android/test/image_picker_android_test.dart @@ -27,8 +27,9 @@ void main() { test('calls the method correctly', () async { const String fakePath = '/foo.jpg'; api.returnValue = [fakePath]; - final PickedFile? result = - await picker.pickImage(source: ImageSource.camera); + final PickedFile? result = await picker.pickImage( + source: ImageSource.camera, + ); expect(result?.path, fakePath); expect(api.lastCall, _LastPickType.image); @@ -117,8 +118,9 @@ void main() { test('camera position can be set to front', () async { await picker.pickImage( - source: ImageSource.camera, - preferredCameraDevice: CameraDevice.front); + source: ImageSource.camera, + preferredCameraDevice: CameraDevice.front, + ); expect(api.passedSource?.camera, SourceCamera.front); }); @@ -173,15 +175,9 @@ void main() { }); test('does not accept a negative width or height argument', () { - expect( - () => picker.pickMultiImage(maxWidth: -1.0), - throwsArgumentError, - ); + expect(() => picker.pickMultiImage(maxWidth: -1.0), throwsArgumentError); - expect( - () => picker.pickMultiImage(maxHeight: -1.0), - throwsArgumentError, - ); + expect(() => picker.pickMultiImage(maxHeight: -1.0), throwsArgumentError); }); test('does not accept an invalid imageQuality argument', () { @@ -220,8 +216,9 @@ void main() { test('calls the method correctly', () async { const String fakePath = '/foo.jpg'; api.returnValue = [fakePath]; - final PickedFile? result = - await picker.pickVideo(source: ImageSource.camera); + final PickedFile? result = await picker.pickVideo( + source: ImageSource.camera, + ); expect(result?.path, fakePath); expect(api.lastCall, _LastPickType.video); @@ -295,7 +292,9 @@ void main() { group('#retrieveLostData', () { test('retrieveLostData get success response', () async { api.returnValue = CacheRetrievalResult( - type: CacheRetrievalType.image, paths: ['/example/path']); + type: CacheRetrievalType.image, + paths: ['/example/path'], + ); final LostData response = await picker.retrieveLostData(); expect(response.type, RetrieveType.image); @@ -305,10 +304,13 @@ void main() { test('retrieveLostData get error response', () async { api.returnValue = CacheRetrievalResult( - type: CacheRetrievalType.video, - paths: [], - error: CacheRetrievalError( - code: 'test_error_code', message: 'test_error_message')); + type: CacheRetrievalType.video, + paths: [], + error: CacheRetrievalError( + code: 'test_error_code', + message: 'test_error_message', + ), + ); final LostData response = await picker.retrieveLostData(); expect(response.type, RetrieveType.video); @@ -325,10 +327,13 @@ void main() { test('retrieveLostData get both path and error should throw', () async { api.returnValue = CacheRetrievalResult( - type: CacheRetrievalType.video, - paths: ['/example/path'], - error: CacheRetrievalError( - code: 'test_error_code', message: 'test_error_message')); + type: CacheRetrievalType.video, + paths: ['/example/path'], + error: CacheRetrievalError( + code: 'test_error_code', + message: 'test_error_message', + ), + ); expect(picker.retrieveLostData(), throwsAssertionError); }); @@ -427,8 +432,9 @@ void main() { test('camera position can set to front', () async { await picker.getImage( - source: ImageSource.camera, - preferredCameraDevice: CameraDevice.front); + source: ImageSource.camera, + preferredCameraDevice: CameraDevice.front, + ); expect(api.passedSource?.camera, SourceCamera.front); }); @@ -483,22 +489,13 @@ void main() { }); test('does not accept a negative width or height argument', () { - expect( - () => picker.getMultiImage(maxWidth: -1.0), - throwsArgumentError, - ); + expect(() => picker.getMultiImage(maxWidth: -1.0), throwsArgumentError); - expect( - () => picker.getMultiImage(maxHeight: -1.0), - throwsArgumentError, - ); + expect(() => picker.getMultiImage(maxHeight: -1.0), throwsArgumentError); }); test('does not accept an invalid imageQuality argument', () { - expect( - () => picker.getMultiImage(imageQuality: -1), - throwsArgumentError, - ); + expect(() => picker.getMultiImage(imageQuality: -1), throwsArgumentError); expect( () => picker.getMultiImage(imageQuality: 101), @@ -617,10 +614,11 @@ void main() { test('passes the arguments correctly', () async { api.returnValue = []; await picker.getMultiVideoWithOptions( - options: const MultiVideoPickerOptions( - maxDuration: Duration(seconds: 10), - limit: 5, - )); + options: const MultiVideoPickerOptions( + maxDuration: Duration(seconds: 10), + limit: 5, + ), + ); expect(api.passedSource?.type, SourceType.gallery); expect(api.passedVideoOptions?.maxDurationSeconds, 10); @@ -631,7 +629,9 @@ void main() { group('#getLostData', () { test('getLostData get success response', () async { api.returnValue = CacheRetrievalResult( - type: CacheRetrievalType.image, paths: ['/example/path']); + type: CacheRetrievalType.image, + paths: ['/example/path'], + ); final LostDataResponse response = await picker.getLostData(); expect(response.type, RetrieveType.image); @@ -641,8 +641,9 @@ void main() { test('getLostData should successfully retrieve multiple files', () async { api.returnValue = CacheRetrievalResult( - type: CacheRetrievalType.image, - paths: ['/example/path0', '/example/path1']); + type: CacheRetrievalType.image, + paths: ['/example/path0', '/example/path1'], + ); final LostDataResponse response = await picker.getLostData(); expect(response.type, RetrieveType.image); @@ -654,10 +655,13 @@ void main() { test('getLostData get error response', () async { api.returnValue = CacheRetrievalResult( - type: CacheRetrievalType.video, - paths: [], - error: CacheRetrievalError( - code: 'test_error_code', message: 'test_error_message')); + type: CacheRetrievalType.video, + paths: [], + error: CacheRetrievalError( + code: 'test_error_code', + message: 'test_error_message', + ), + ); final LostDataResponse response = await picker.getLostData(); expect(response.type, RetrieveType.video); @@ -674,10 +678,13 @@ void main() { test('getLostData get both path and error should throw', () async { api.returnValue = CacheRetrievalResult( - type: CacheRetrievalType.video, - paths: ['/example/path'], - error: CacheRetrievalError( - code: 'test_error_code', message: 'test_error_message')); + type: CacheRetrievalType.video, + paths: ['/example/path'], + error: CacheRetrievalError( + code: 'test_error_code', + message: 'test_error_message', + ), + ); expect(picker.getLostData(), throwsAssertionError); }); @@ -689,9 +696,7 @@ void main() { api.returnValue = fakePaths; final List files = await picker.getMedia( - options: const MediaOptions( - allowMultiple: true, - ), + options: const MediaOptions(allowMultiple: true), ); expect(api.lastCall, _LastPickType.image); @@ -701,11 +706,7 @@ void main() { }); test('passes default image options', () async { - await picker.getMedia( - options: const MediaOptions( - allowMultiple: true, - ), - ); + await picker.getMedia(options: const MediaOptions(allowMultiple: true)); expect(api.passedImageOptions?.maxWidth, null); expect(api.passedImageOptions?.maxHeight, null); @@ -715,15 +716,16 @@ void main() { test('passes image option arguments correctly', () async { await picker.getMedia( - options: const MediaOptions( - allowMultiple: true, - imageOptions: ImageOptions( - maxWidth: 10.0, - maxHeight: 20.0, - imageQuality: 70, + options: const MediaOptions( + allowMultiple: true, + imageOptions: ImageOptions( + maxWidth: 10.0, + maxHeight: 20.0, + imageQuality: 70, + ), + limit: 5, ), - limit: 5, - )); + ); expect(api.passedImageOptions?.maxWidth, 10.0); expect(api.passedImageOptions?.maxHeight, 20.0); @@ -778,20 +780,14 @@ void main() { test('does not accept an invalid limit argument', () { expect( () => picker.getMedia( - options: const MediaOptions( - allowMultiple: true, - limit: -1, - ), + options: const MediaOptions(allowMultiple: true, limit: -1), ), throwsArgumentError, ); expect( () => picker.getMedia( - options: const MediaOptions( - allowMultiple: true, - limit: 0, - ), + options: const MediaOptions(allowMultiple: true, limit: 0), ), throwsArgumentError, ); @@ -810,31 +806,20 @@ void main() { api.returnValue = []; expect( - await picker.getMedia( - options: const MediaOptions( - allowMultiple: true, - ), - ), - []); + await picker.getMedia(options: const MediaOptions(allowMultiple: true)), + [], + ); }); test('defaults to not using Android Photo Picker', () async { - await picker.getMedia( - options: const MediaOptions( - allowMultiple: true, - ), - ); + await picker.getMedia(options: const MediaOptions(allowMultiple: true)); expect(api.passedPhotoPickerFlag, false); }); test('allows using Android Photo Picker', () async { picker.useAndroidPhotoPicker = true; - await picker.getMedia( - options: const MediaOptions( - allowMultiple: true, - ), - ); + await picker.getMedia(options: const MediaOptions(allowMultiple: true)); expect(api.passedPhotoPickerFlag, true); }); @@ -942,9 +927,13 @@ void main() { api.returnValue = null; expect( - await picker.getImageFromSource(source: ImageSource.gallery), isNull); + await picker.getImageFromSource(source: ImageSource.gallery), + isNull, + ); expect( - await picker.getImageFromSource(source: ImageSource.camera), isNull); + await picker.getImageFromSource(source: ImageSource.camera), + isNull, + ); }); test('camera position defaults to back', () async { @@ -955,9 +944,11 @@ void main() { test('camera position can be set to front', () async { await picker.getImageFromSource( - source: ImageSource.camera, - options: const ImagePickerOptions( - preferredCameraDevice: CameraDevice.front)); + source: ImageSource.camera, + options: const ImagePickerOptions( + preferredCameraDevice: CameraDevice.front, + ), + ); expect(api.passedSource?.camera, SourceCamera.front); }); 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 index 5badb7e147f..b0f4a46568e 100644 --- a/packages/image_picker/image_picker_android/test/test_api.g.dart +++ b/packages/image_picker/image_picker_android/test/test_api.g.dart @@ -93,16 +93,24 @@ abstract class TestHostImagePickerApi { static const MessageCodec pigeonChannelCodec = _PigeonCodec(); /// Selects images and returns their paths. - Future> pickImages(SourceSpecification source, - ImageSelectionOptions options, GeneralOptions generalOptions); + Future> pickImages( + SourceSpecification source, + ImageSelectionOptions options, + GeneralOptions generalOptions, + ); /// Selects video and returns their paths. - Future> pickVideos(SourceSpecification source, - VideoSelectionOptions options, GeneralOptions generalOptions); + Future> pickVideos( + SourceSpecification source, + VideoSelectionOptions options, + GeneralOptions generalOptions, + ); /// Selects images and videos and returns their paths. - Future> pickMedia(MediaSelectionOptions mediaSelectionOptions, - GeneralOptions generalOptions); + Future> pickMedia( + MediaSelectionOptions mediaSelectionOptions, + GeneralOptions generalOptions, + ); /// Returns results from a previous app session, if any. CacheRetrievalResult? retrieveLostResults(); @@ -115,151 +123,189 @@ abstract class TestHostImagePickerApi { messageChannelSuffix = messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; { - final BasicMessageChannel< - Object?> pigeonVar_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.image_picker_android.ImagePickerApi.pickImages$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); + 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(pigeonVar_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.image_picker_android.ImagePickerApi.pickImages was null.'); + _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.'); + 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.'); + 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.'); + 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!); + 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())); + error: PlatformException(code: 'error', message: e.toString()), + ); } }); } } { - final BasicMessageChannel< - Object?> pigeonVar_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.image_picker_android.ImagePickerApi.pickVideos$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); + 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(pigeonVar_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.image_picker_android.ImagePickerApi.pickVideos was null.'); + _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.'); + 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.'); + 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.'); + 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!); + 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())); + error: PlatformException(code: 'error', message: e.toString()), + ); } }); } } { - final BasicMessageChannel< - Object?> pigeonVar_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.image_picker_android.ImagePickerApi.pickMedia$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); + 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(pigeonVar_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.image_picker_android.ImagePickerApi.pickMedia was null.'); + _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.'); + 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.'); + 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!); + 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())); + error: PlatformException(code: 'error', message: e.toString()), + ); } }); } } { - final BasicMessageChannel< - Object?> pigeonVar_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.image_picker_android.ImagePickerApi.retrieveLostResults$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); + 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())); - } - }); + .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_for_web/CHANGELOG.md b/packages/image_picker/image_picker_for_web/CHANGELOG.md index 04fffb8f67b..4abc12d19aa 100644 --- a/packages/image_picker/image_picker_for_web/CHANGELOG.md +++ b/packages/image_picker/image_picker_for_web/CHANGELOG.md @@ -1,3 +1,7 @@ +## NEXT + +* Updates minimum supported SDK version to Flutter 3.29/Dart 3.7. + ## 3.1.0 * Adds support for `getMultiVideoWithOptions`. diff --git a/packages/image_picker/image_picker_for_web/example/integration_test/image_picker_for_web_test.dart b/packages/image_picker/image_picker_for_web/example/integration_test/image_picker_for_web_test.dart index 3d265b6632d..ad52d45b30e 100644 --- a/packages/image_picker/image_picker_for_web/example/integration_test/image_picker_for_web_test.dart +++ b/packages/image_picker/image_picker_for_web/example/integration_test/image_picker_for_web_test.dart @@ -22,10 +22,15 @@ final web.FilePropertyBag options = web.FilePropertyBag( lastModified: DateTime.utc(2017, 12, 13).millisecondsSinceEpoch, )..type = 'text/plain'; -final web.File textFile = - web.File([bytes.toJS].toJS, 'hello.txt', options); -final web.File secondTextFile = - web.File([otherBytes.toJS].toJS, 'secondFile.txt'); +final web.File textFile = web.File( + [bytes.toJS].toJS, + 'hello.txt', + options, +); +final web.File secondTextFile = web.File( + [otherBytes.toJS].toJS, + 'secondFile.txt', +); void main() { IntegrationTestWidgetsFlutterBinding.ensureInitialized(); @@ -37,11 +42,9 @@ void main() { plugin = ImagePickerPlugin(); }); - testWidgets('getImageFromSource can select a file', ( - WidgetTester _, - ) async { - final web.HTMLInputElement mockInput = web.HTMLInputElement() - ..type = 'file'; + testWidgets('getImageFromSource can select a file', (WidgetTester _) async { + final web.HTMLInputElement mockInput = + web.HTMLInputElement()..type = 'file'; final ImagePickerPluginTestOverrides overrides = ImagePickerPluginTestOverrides() ..createInputElement = ((_, __) => mockInput) @@ -55,8 +58,9 @@ void main() { ); expect( - web.document.querySelector('flt-image-picker-inputs')?.children.length, - isNonZero); + web.document.querySelector('flt-image-picker-inputs')?.children.length, + isNonZero, + ); // Mock the browser behavior of selecting a file... mockInput.dispatchEvent(web.Event('change')); @@ -72,20 +76,20 @@ void main() { expect(file.length(), completion(textFile.size)); expect(file.mimeType, textFile.type); expect( - file.lastModified(), - completion( - DateTime.fromMillisecondsSinceEpoch(textFile.lastModified), - )); + file.lastModified(), + completion(DateTime.fromMillisecondsSinceEpoch(textFile.lastModified)), + ); expect( - web.document.querySelector('flt-image-picker-inputs')?.children.length, - isZero); + web.document.querySelector('flt-image-picker-inputs')?.children.length, + isZero, + ); }); testWidgets('getMultiImageWithOptions can select multiple files', ( WidgetTester _, ) async { - final web.HTMLInputElement mockInput = web.HTMLInputElement() - ..type = 'file'; + final web.HTMLInputElement mockInput = + web.HTMLInputElement()..type = 'file'; final ImagePickerPluginTestOverrides overrides = ImagePickerPluginTestOverrides() @@ -115,8 +119,8 @@ void main() { }); testWidgets('getMedia can select multiple files', (WidgetTester _) async { - final web.HTMLInputElement mockInput = web.HTMLInputElement() - ..type = 'file'; + final web.HTMLInputElement mockInput = + web.HTMLInputElement()..type = 'file'; final ImagePickerPluginTestOverrides overrides = ImagePickerPluginTestOverrides() @@ -127,8 +131,9 @@ void main() { final ImagePickerPlugin plugin = ImagePickerPlugin(overrides: overrides); // Init the pick file dialog... - final Future> files = - plugin.getMedia(options: const MediaOptions(allowMultiple: true)); + final Future> files = plugin.getMedia( + options: const MediaOptions(allowMultiple: true), + ); // Mock the browser behavior of selecting a file... mockInput.dispatchEvent(web.Event('change')); @@ -149,8 +154,8 @@ void main() { testWidgets('getMultiVideoWithOptions can select multiple files', ( WidgetTester _, ) async { - final web.HTMLInputElement mockInput = web.HTMLInputElement() - ..type = 'file'; + final web.HTMLInputElement mockInput = + web.HTMLInputElement()..type = 'file'; final ImagePickerPluginTestOverrides overrides = ImagePickerPluginTestOverrides() @@ -186,9 +191,10 @@ void main() { setUp(() { mockInput = web.HTMLInputElement()..type = 'file'; - overrides = ImagePickerPluginTestOverrides() - ..createInputElement = ((_, __) => mockInput) - ..getMultipleFilesFromInput = ((_) => [textFile]); + overrides = + ImagePickerPluginTestOverrides() + ..createInputElement = ((_, __) => mockInput) + ..getMultipleFilesFromInput = ((_) => [textFile]); plugin = ImagePickerPlugin(overrides: overrides); }); @@ -206,9 +212,8 @@ void main() { testWidgets('getMedia - returns empty list', (WidgetTester _) async { final Future?> files = plugin.getMedia( - options: const MediaOptions( - allowMultiple: true, - )); + options: const MediaOptions(allowMultiple: true), + ); mockCancel(); expect(files, completes); @@ -236,9 +241,7 @@ void main() { }); testWidgets('getVideo - returns null', (WidgetTester _) async { - final Future file = plugin.getVideo( - source: ImageSource.gallery, - ); + final Future file = plugin.getVideo(source: ImageSource.gallery); mockCancel(); expect(file, completes); @@ -292,20 +295,28 @@ void main() { expect(input.hasAttribute('multiple'), false); }); - testWidgets('accept: any, capture: null, multi: true', - (WidgetTester tester) async { - final web.Element input = - plugin.createInputElement('any', null, multiple: true); + testWidgets('accept: any, capture: null, multi: true', ( + WidgetTester tester, + ) async { + final web.Element input = plugin.createInputElement( + 'any', + null, + multiple: true, + ); expect(input.getAttribute('accept'), 'any'); expect(input.hasAttribute('capture'), false); expect(input.hasAttribute('multiple'), true); }); - testWidgets('accept: any, capture: something, multi: true', - (WidgetTester tester) async { - final web.Element input = - plugin.createInputElement('any', 'something', multiple: true); + testWidgets('accept: any, capture: something, multi: true', ( + WidgetTester tester, + ) async { + final web.Element input = plugin.createInputElement( + 'any', + 'something', + multiple: true, + ); expect(input.getAttribute('accept'), 'any'); expect(input.getAttribute('capture'), 'something'); @@ -320,9 +331,10 @@ void main() { setUp(() { mockInput = web.HTMLInputElement()..type = 'file'; - overrides = ImagePickerPluginTestOverrides() - ..createInputElement = ((_, __) => mockInput) - ..getMultipleFilesFromInput = ((_) => [textFile]); + overrides = + ImagePickerPluginTestOverrides() + ..createInputElement = ((_, __) => mockInput) + ..getMultipleFilesFromInput = ((_) => [textFile]); plugin = ImagePickerPlugin(overrides: overrides); }); @@ -355,10 +367,11 @@ void main() { expect(file.length(), completion(textFile.size)); expect(file.mimeType, textFile.type); expect( - file.lastModified(), - completion( - DateTime.fromMillisecondsSinceEpoch(textFile.lastModified), - )); + file.lastModified(), + completion( + DateTime.fromMillisecondsSinceEpoch(textFile.lastModified), + ), + ); }); testWidgets('returns null when canceled', (WidgetTester _) async { diff --git a/packages/image_picker/image_picker_for_web/example/integration_test/image_resizer_test.dart b/packages/image_picker/image_picker_for_web/example/integration_test/image_resizer_test.dart index 33f397a8c79..07cfe1978ae 100644 --- a/packages/image_picker/image_picker_for_web/example/integration_test/image_resizer_test.dart +++ b/packages/image_picker/image_picker_for_web/example/integration_test/image_resizer_test.dart @@ -26,86 +26,133 @@ void main() { setUp(() { imageResizer = ImageResizer(); final web.Blob pngHtmlFile = _base64ToBlob(pngFileBase64Contents); - pngFile = XFile(web.URL.createObjectURL(pngHtmlFile), - name: 'pngImage.png', mimeType: 'image/png'); + pngFile = XFile( + web.URL.createObjectURL(pngHtmlFile), + name: 'pngImage.png', + mimeType: 'image/png', + ); }); testWidgets('image is loaded correctly ', (WidgetTester tester) async { - final web.HTMLImageElement imageElement = - await imageResizer.loadImage(pngFile.path); + final web.HTMLImageElement imageElement = await imageResizer.loadImage( + pngFile.path, + ); expect(imageElement.width, 10); expect(imageElement.height, 10); }); testWidgets( - "canvas is loaded with image's width and height when max width and max height are null", - (WidgetTester widgetTester) async { - final web.HTMLImageElement imageElement = - await imageResizer.loadImage(pngFile.path); - final web.HTMLCanvasElement canvas = - imageResizer.resizeImageElement(imageElement, null, null); - expect(canvas.width, imageElement.width); - expect(canvas.height, imageElement.height); - }); + "canvas is loaded with image's width and height when max width and max height are null", + (WidgetTester widgetTester) async { + final web.HTMLImageElement imageElement = await imageResizer.loadImage( + pngFile.path, + ); + final web.HTMLCanvasElement canvas = imageResizer.resizeImageElement( + imageElement, + null, + null, + ); + expect(canvas.width, imageElement.width); + expect(canvas.height, imageElement.height); + }, + ); testWidgets( - 'canvas size is scaled when max width and max height are not null', - (WidgetTester widgetTester) async { - final web.HTMLImageElement imageElement = - await imageResizer.loadImage(pngFile.path); - final web.HTMLCanvasElement canvas = - imageResizer.resizeImageElement(imageElement, 8, 8); - expect(canvas.width, 8); - expect(canvas.height, 8); - }); - - testWidgets('resized image is returned after converting canvas to file', - (WidgetTester widgetTester) async { - final web.HTMLImageElement imageElement = - await imageResizer.loadImage(pngFile.path); - final web.HTMLCanvasElement canvas = - imageResizer.resizeImageElement(imageElement, null, null); - final XFile resizedImage = - await imageResizer.writeCanvasToFile(pngFile, canvas, null); + 'canvas size is scaled when max width and max height are not null', + (WidgetTester widgetTester) async { + final web.HTMLImageElement imageElement = await imageResizer.loadImage( + pngFile.path, + ); + final web.HTMLCanvasElement canvas = imageResizer.resizeImageElement( + imageElement, + 8, + 8, + ); + expect(canvas.width, 8); + expect(canvas.height, 8); + }, + ); + + testWidgets('resized image is returned after converting canvas to file', ( + WidgetTester widgetTester, + ) async { + final web.HTMLImageElement imageElement = await imageResizer.loadImage( + pngFile.path, + ); + final web.HTMLCanvasElement canvas = imageResizer.resizeImageElement( + imageElement, + null, + null, + ); + final XFile resizedImage = await imageResizer.writeCanvasToFile( + pngFile, + canvas, + null, + ); expect(resizedImage.name, 'scaled_${pngFile.name}'); }); - testWidgets('image is scaled when maxWidth is set', - (WidgetTester tester) async { - final XFile scaledImage = - await imageResizer.resizeImageIfNeeded(pngFile, 5, null, null); + testWidgets('image is scaled when maxWidth is set', ( + WidgetTester tester, + ) async { + final XFile scaledImage = await imageResizer.resizeImageIfNeeded( + pngFile, + 5, + null, + null, + ); expect(scaledImage.name, 'scaled_${pngFile.name}'); final Size scaledImageSize = await _getImageSize(scaledImage); expect(scaledImageSize, const Size(5, 5)); }); - testWidgets('image is scaled when maxHeight is set', - (WidgetTester tester) async { - final XFile scaledImage = - await imageResizer.resizeImageIfNeeded(pngFile, null, 6, null); + testWidgets('image is scaled when maxHeight is set', ( + WidgetTester tester, + ) async { + final XFile scaledImage = await imageResizer.resizeImageIfNeeded( + pngFile, + null, + 6, + null, + ); expect(scaledImage.name, 'scaled_${pngFile.name}'); final Size scaledImageSize = await _getImageSize(scaledImage); expect(scaledImageSize, const Size(6, 6)); }); - testWidgets('image is scaled when imageQuality is set', - (WidgetTester tester) async { - final XFile scaledImage = - await imageResizer.resizeImageIfNeeded(pngFile, null, null, 89); + testWidgets('image is scaled when imageQuality is set', ( + WidgetTester tester, + ) async { + final XFile scaledImage = await imageResizer.resizeImageIfNeeded( + pngFile, + null, + null, + 89, + ); expect(scaledImage.name, 'scaled_${pngFile.name}'); }); - testWidgets('image is scaled when maxWidth,maxHeight,imageQuality are set', - (WidgetTester tester) async { - final XFile scaledImage = - await imageResizer.resizeImageIfNeeded(pngFile, 3, 4, 89); + testWidgets('image is scaled when maxWidth,maxHeight,imageQuality are set', ( + WidgetTester tester, + ) async { + final XFile scaledImage = await imageResizer.resizeImageIfNeeded( + pngFile, + 3, + 4, + 89, + ); expect(scaledImage.name, 'scaled_${pngFile.name}'); }); - testWidgets('image is not scaled when maxWidth,maxHeight, is set', - (WidgetTester tester) async { - final XFile scaledImage = - await imageResizer.resizeImageIfNeeded(pngFile, null, null, null); + testWidgets('image is not scaled when maxWidth,maxHeight, is set', ( + WidgetTester tester, + ) async { + final XFile scaledImage = await imageResizer.resizeImageIfNeeded( + pngFile, + null, + null, + null, + ); expect(scaledImage.name, pngFile.name); }); } diff --git a/packages/image_picker/image_picker_for_web/example/integration_test/readme_excerpts_test.dart b/packages/image_picker/image_picker_for_web/example/integration_test/readme_excerpts_test.dart index 65c1081dfb8..41da02a6d3c 100644 --- a/packages/image_picker/image_picker_for_web/example/integration_test/readme_excerpts_test.dart +++ b/packages/image_picker/image_picker_for_web/example/integration_test/readme_excerpts_test.dart @@ -15,8 +15,9 @@ import 'package:integration_test/integration_test.dart'; void main() { IntegrationTestWidgetsFlutterBinding.ensureInitialized(); - testWidgets('getImageFromPath loads image from XFile path', - (WidgetTester tester) async { + testWidgets('getImageFromPath loads image from XFile path', ( + WidgetTester tester, + ) async { final XFile file = createXFileWeb(); // Use the excerpt code to get an Image from the XFile path. @@ -28,8 +29,9 @@ void main() { expect(find.byType(Image), findsOneWidget); }); - testWidgets('getImageFromBytes loads image from XFile bytes', - (WidgetTester tester) async { + testWidgets('getImageFromBytes loads image from XFile bytes', ( + WidgetTester tester, + ) async { final XFile file = createXFileWeb(); // Use the excerpt code to get an Image from the XFile byte data. @@ -44,7 +46,8 @@ void main() { /// Creates an XFile with a 1x1 png file. XFile createXFileWeb() { - const String pixel = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR' + const String pixel = + 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR' '42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII='; final Uint8List data = base64Decode(pixel); return XFile.fromData( @@ -57,9 +60,5 @@ XFile createXFileWeb() { /// Pumps an [image] widget into a [tester]. Future pumpImage(WidgetTester tester, Image image) async { - await tester.pumpWidget(MaterialApp( - home: Scaffold( - body: image, - ), - )); + await tester.pumpWidget(MaterialApp(home: Scaffold(body: image))); } diff --git a/packages/image_picker/image_picker_for_web/example/lib/readme_excerpts.dart b/packages/image_picker/image_picker_for_web/example/lib/readme_excerpts.dart index 4ad3100e97e..ba9162a41de 100644 --- a/packages/image_picker/image_picker_for_web/example/lib/readme_excerpts.dart +++ b/packages/image_picker/image_picker_for_web/example/lib/readme_excerpts.dart @@ -12,13 +12,13 @@ import 'package:image_picker_platform_interface/image_picker_platform_interface. Image getImageFromPath(XFile pickedFile) { final Image image; -// #docregion ImageFromPath + // #docregion ImageFromPath if (kIsWeb) { image = Image.network(pickedFile.path); } else { image = Image.file(File(pickedFile.path)); } -// #enddocregion ImageFromPath + // #enddocregion ImageFromPath return image; } @@ -27,9 +27,9 @@ Image getImageFromPath(XFile pickedFile) { Future getImageFromBytes(XFile pickedFile) async { final Image image; -// #docregion ImageFromBytes + // #docregion ImageFromBytes image = Image.memory(await pickedFile.readAsBytes()); -// #enddocregion ImageFromBytes + // #enddocregion ImageFromBytes return image; } diff --git a/packages/image_picker/image_picker_for_web/example/pubspec.yaml b/packages/image_picker/image_picker_for_web/example/pubspec.yaml index ff13bae933c..03f55db879e 100644 --- a/packages/image_picker/image_picker_for_web/example/pubspec.yaml +++ b/packages/image_picker/image_picker_for_web/example/pubspec.yaml @@ -2,8 +2,8 @@ name: image_picker_for_web_integration_tests publish_to: none environment: - sdk: ^3.6.0 - flutter: ">=3.27.0" + sdk: ^3.7.0 + flutter: ">=3.29.0" dependencies: flutter: diff --git a/packages/image_picker/image_picker_for_web/lib/image_picker_for_web.dart b/packages/image_picker/image_picker_for_web/lib/image_picker_for_web.dart index 3b515babeb3..7beb611753e 100644 --- a/packages/image_picker/image_picker_for_web/lib/image_picker_for_web.dart +++ b/packages/image_picker/image_picker_for_web/lib/image_picker_for_web.dart @@ -50,8 +50,10 @@ class ImagePickerPlugin extends ImagePickerPlatform { required ImageSource source, ImagePickerOptions options = const ImagePickerOptions(), }) async { - final String? capture = - computeCaptureAttribute(source, options.preferredCameraDevice); + final String? capture = computeCaptureAttribute( + source, + options.preferredCameraDevice, + ); final List files = await getFiles( accept: _kAcceptImageMimeType, capture: capture, @@ -59,11 +61,11 @@ class ImagePickerPlugin extends ImagePickerPlatform { return files.isEmpty ? null : _imageResizer.resizeImageIfNeeded( - files.first, - options.maxWidth, - options.maxHeight, - options.imageQuality, - ); + files.first, + options.maxWidth, + options.maxHeight, + options.imageQuality, + ); } /// Returns a [List] with the images that were picked, if any. @@ -105,8 +107,10 @@ class ImagePickerPlugin extends ImagePickerPlatform { CameraDevice preferredCameraDevice = CameraDevice.rear, Duration? maxDuration, }) async { - final String? capture = - computeCaptureAttribute(source, preferredCameraDevice); + final String? capture = computeCaptureAttribute( + source, + preferredCameraDevice, + ); final List files = await getFiles( accept: _kAcceptVideoMimeType, capture: capture, @@ -127,9 +131,7 @@ class ImagePickerPlugin extends ImagePickerPlatform { /// Injects a file input, and returns a list of XFile media that the user selected locally. @override - Future> getMedia({ - required MediaOptions options, - }) async { + Future> getMedia({required MediaOptions options}) async { final List images = await getFiles( accept: '$_kAcceptImageMimeType,$_kAcceptVideoMimeType', multiple: options.allowMultiple, @@ -200,13 +202,14 @@ class ImagePickerPlugin extends ImagePickerPlatform { CameraDevice preferredCameraDevice = CameraDevice.rear, }) async { return getImageFromSource( - source: source, - options: ImagePickerOptions( - maxWidth: maxWidth, - maxHeight: maxHeight, - imageQuality: imageQuality, - preferredCameraDevice: preferredCameraDevice, - )); + source: source, + options: ImagePickerOptions( + maxWidth: maxWidth, + maxHeight: maxHeight, + imageQuality: imageQuality, + preferredCameraDevice: preferredCameraDevice, + ), + ); } /// Injects a file input, and returns a list of XFile images that the user selected locally. @@ -261,32 +264,37 @@ class ImagePickerPlugin extends ImagePickerPlatform { // TODO(dit): Migrate all this to Streams (onChange, onError, onCancel) when onCancel is available. // See: https://github.com/dart-lang/web/issues/199 // Observe the input until we can return something - input.onchange = (web.Event event) { - final List? files = _handleOnChangeEvent(event); - if (!completer.isCompleted && files != null) { - completer.complete(files.map((web.File file) { - return XFile( - web.URL.createObjectURL(file), - name: file.name, - length: file.size, - lastModified: DateTime.fromMillisecondsSinceEpoch( - file.lastModified, - ), - mimeType: file.type, - ); - }).toList()); - } - }.toJS; - - input.oncancel = (web.Event _) { - completer.complete([]); - }.toJS; - - input.onerror = (web.Event event) { - if (!completer.isCompleted) { - completer.completeError(event); - } - }.toJS; + input.onchange = + (web.Event event) { + final List? files = _handleOnChangeEvent(event); + if (!completer.isCompleted && files != null) { + completer.complete( + files.map((web.File file) { + return XFile( + web.URL.createObjectURL(file), + name: file.name, + length: file.size, + lastModified: DateTime.fromMillisecondsSinceEpoch( + file.lastModified, + ), + mimeType: file.type, + ); + }).toList(), + ); + } + }.toJS; + + input.oncancel = + (web.Event _) { + completer.complete([]); + }.toJS; + + input.onerror = + (web.Event event) { + if (!completer.isCompleted) { + completer.completeError(event); + } + }.toJS; // Note that we don't bother detaching from these streams, since the // "input" gets re-created in the DOM every time the user needs to // pick a file. @@ -297,8 +305,9 @@ class ImagePickerPlugin extends ImagePickerPlatform { web.Element _ensureInitialized(String id) { web.Element? target = web.document.querySelector('#$id'); if (target == null) { - final web.Element targetElement = - web.document.createElement('flt-image-picker-inputs')..id = id; + final web.Element targetElement = web.document.createElement( + 'flt-image-picker-inputs', + )..id = id; // TODO(ditman): Append inside the `view` of the running app. web.document.body!.append(targetElement); target = targetElement; @@ -318,9 +327,10 @@ class ImagePickerPlugin extends ImagePickerPlatform { return _overrides!.createInputElement(accept, capture); } - final web.HTMLInputElement element = web.HTMLInputElement() - ..type = 'file' - ..multiple = multiple; + final web.HTMLInputElement element = + web.HTMLInputElement() + ..type = 'file' + ..multiple = multiple; if (accept != null) { element.accept = accept; @@ -345,15 +355,13 @@ class ImagePickerPlugin extends ImagePickerPlatform { // Some tools to override behavior for unit-testing /// A function that creates a file input with the passed in `accept` and `capture` attributes. @visibleForTesting -typedef OverrideCreateInputFunction = web.HTMLInputElement Function( - String? accept, - String? capture, -); +typedef OverrideCreateInputFunction = + web.HTMLInputElement Function(String? accept, String? capture); /// A function that extracts list of files from the file `input` passed in. @visibleForTesting -typedef OverrideExtractMultipleFilesFromInputFunction = List Function( - web.HTMLInputElement? input); +typedef OverrideExtractMultipleFilesFromInputFunction = + List Function(web.HTMLInputElement? input); /// Overrides for some of the functionality above. @visibleForTesting diff --git a/packages/image_picker/image_picker_for_web/lib/src/image_resizer.dart b/packages/image_picker/image_picker_for_web/lib/src/image_resizer.dart index 8cba8cfe91d..0a4c1793695 100644 --- a/packages/image_picker/image_picker_for_web/lib/src/image_resizer.dart +++ b/packages/image_picker/image_picker_for_web/lib/src/image_resizer.dart @@ -30,10 +30,16 @@ class ImageResizer { } try { final web.HTMLImageElement imageElement = await loadImage(file.path); - final web.HTMLCanvasElement canvas = - resizeImageElement(imageElement, maxWidth, maxHeight); - final XFile resizedImage = - await writeCanvasToFile(file, canvas, imageQuality); + final web.HTMLCanvasElement canvas = resizeImageElement( + imageElement, + maxWidth, + maxHeight, + ); + final XFile resizedImage = await writeCanvasToFile( + file, + canvas, + imageQuality, + ); web.URL.revokeObjectURL(file.path); return resizedImage; } catch (e) { @@ -66,18 +72,25 @@ class ImageResizer { double? maxHeight, ) { final Size newImageSize = calculateSizeOfDownScaledImage( - Size(source.width.toDouble(), source.height.toDouble()), - maxWidth, - maxHeight); - final web.HTMLCanvasElement canvas = web.HTMLCanvasElement() - ..width = newImageSize.width.toInt() - ..height = newImageSize.height.toInt(); + Size(source.width.toDouble(), source.height.toDouble()), + maxWidth, + maxHeight, + ); + final web.HTMLCanvasElement canvas = + web.HTMLCanvasElement() + ..width = newImageSize.width.toInt() + ..height = newImageSize.height.toInt(); final web.CanvasRenderingContext2D context = canvas.context2D; if (maxHeight == null && maxWidth == null) { context.drawImage(source, 0, 0); } else { context.drawImageScaled( - source, 0, 0, canvas.width.toDouble(), canvas.height.toDouble()); + source, + 0, + 0, + canvas.width.toDouble(), + canvas.height.toDouble(), + ); } return canvas; } @@ -93,15 +106,23 @@ class ImageResizer { final double calculatedImageQuality = (min(imageQuality ?? 100, 100)) / 100.0; final Completer completer = Completer(); - final web.BlobCallback blobCallback = (web.Blob blob) { - completer.complete(XFile(web.URL.createObjectURL(blob), - mimeType: originalFile.mimeType, - name: 'scaled_${originalFile.name}', - lastModified: DateTime.now(), - length: blob.size)); - }.toJS; + final web.BlobCallback blobCallback = + (web.Blob blob) { + completer.complete( + XFile( + web.URL.createObjectURL(blob), + mimeType: originalFile.mimeType, + name: 'scaled_${originalFile.name}', + lastModified: DateTime.now(), + length: blob.size, + ), + ); + }.toJS; canvas.toBlob( - blobCallback, originalFile.mimeType ?? '', calculatedImageQuality.toJS); + blobCallback, + originalFile.mimeType ?? '', + calculatedImageQuality.toJS, + ); return completer.future; } } diff --git a/packages/image_picker/image_picker_for_web/lib/src/image_resizer_utils.dart b/packages/image_picker/image_picker_for_web/lib/src/image_resizer_utils.dart index e906a88f00f..ca7bc2d3d2a 100644 --- a/packages/image_picker/image_picker_for_web/lib/src/image_resizer_utils.dart +++ b/packages/image_picker/image_picker_for_web/lib/src/image_resizer_utils.dart @@ -25,7 +25,10 @@ bool isImageQualityValid(int imageQuality) { /// maxWidth is the maximum width of the scaled image /// maxHeight is the maximum height of the scaled image Size calculateSizeOfDownScaledImage( - Size imageSize, double? maxWidth, double? maxHeight) { + Size imageSize, + double? maxWidth, + double? maxHeight, +) { final double widthFactor = maxWidth != null ? imageSize.width / maxWidth : 1; final double heightFactor = maxHeight != null ? imageSize.height / maxHeight : 1; diff --git a/packages/image_picker/image_picker_for_web/lib/src/pkg_web_tweaks.dart b/packages/image_picker/image_picker_for_web/lib/src/pkg_web_tweaks.dart index 1152b01b2d4..06438f8bec2 100644 --- a/packages/image_picker/image_picker_for_web/lib/src/pkg_web_tweaks.dart +++ b/packages/image_picker/image_picker_for_web/lib/src/pkg_web_tweaks.dart @@ -9,6 +9,7 @@ extension WebFileListToDartList on web.FileList { /// Converts a [web.FileList] into a [List] of [web.File]. /// /// This method makes a copy. - List get toList => - [for (int i = 0; i < length; i++) item(i)!]; + List get toList => [ + for (int i = 0; i < length; i++) item(i)!, + ]; } diff --git a/packages/image_picker/image_picker_for_web/pubspec.yaml b/packages/image_picker/image_picker_for_web/pubspec.yaml index 98e86decbb3..a9f2f70d506 100644 --- a/packages/image_picker/image_picker_for_web/pubspec.yaml +++ b/packages/image_picker/image_picker_for_web/pubspec.yaml @@ -5,8 +5,8 @@ issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+ version: 3.1.0 environment: - sdk: ^3.6.0 - flutter: ">=3.27.0" + sdk: ^3.7.0 + flutter: ">=3.29.0" flutter: plugin: diff --git a/packages/image_picker/image_picker_for_web/test/image_resizer_utils_test.dart b/packages/image_picker/image_picker_for_web/test/image_resizer_utils_test.dart index 0bfa81729bf..cbba6fa82b8 100644 --- a/packages/image_picker/image_picker_for_web/test/image_resizer_utils_test.dart +++ b/packages/image_picker/image_picker_for_web/test/image_resizer_utils_test.dart @@ -10,24 +10,33 @@ void main() { group('Image Resizer Utils', () { group('calculateSizeOfScaledImage', () { test( - "scaled image height and width are same if max width and max height are same as image's width and height", - () { - expect(calculateSizeOfDownScaledImage(const Size(500, 300), 500, 300), - const Size(500, 300)); - }); + "scaled image height and width are same if max width and max height are same as image's width and height", + () { + expect( + calculateSizeOfDownScaledImage(const Size(500, 300), 500, 300), + const Size(500, 300), + ); + }, + ); test( - 'scaled image height and width are same if max width and max height are null', - () { - expect(calculateSizeOfDownScaledImage(const Size(500, 300), null, null), - const Size(500, 300)); - }); + 'scaled image height and width are same if max width and max height are null', + () { + expect( + calculateSizeOfDownScaledImage(const Size(500, 300), null, null), + const Size(500, 300), + ); + }, + ); test('image size is scaled when maxWidth is set', () { const Size imageSize = Size(500, 300); const int maxWidth = 400; final Size scaledSize = calculateSizeOfDownScaledImage( - Size(imageSize.width, imageSize.height), maxWidth.toDouble(), null); + Size(imageSize.width, imageSize.height), + maxWidth.toDouble(), + null, + ); expect(scaledSize.height <= imageSize.height, true); expect(scaledSize.width <= maxWidth, true); }); @@ -36,9 +45,10 @@ void main() { const Size imageSize = Size(500, 300); const int maxHeight = 400; final Size scaledSize = calculateSizeOfDownScaledImage( - Size(imageSize.width, imageSize.height), - null, - maxHeight.toDouble()); + Size(imageSize.width, imageSize.height), + null, + maxHeight.toDouble(), + ); expect(scaledSize.height <= maxHeight, true); expect(scaledSize.width <= imageSize.width, true); }); @@ -48,9 +58,10 @@ void main() { const int maxHeight = 1200; const int maxWidth = 99; final Size scaledSize = calculateSizeOfDownScaledImage( - Size(imageSize.width, imageSize.height), - maxWidth.toDouble(), - maxHeight.toDouble()); + Size(imageSize.width, imageSize.height), + maxWidth.toDouble(), + maxHeight.toDouble(), + ); expect(scaledSize.height <= maxHeight, true); expect(scaledSize.width <= maxWidth, true); }); @@ -82,11 +93,12 @@ void main() { }); test( - 'image quality is not valid when imageQuality is less than 0 or greater than 100', - () { - expect(isImageQualityValid(-1), false); - expect(isImageQualityValid(101), false); - }); + 'image quality is not valid when imageQuality is less than 0 or greater than 100', + () { + expect(isImageQualityValid(-1), false); + expect(isImageQualityValid(101), false); + }, + ); }); }); } diff --git a/packages/image_picker/image_picker_ios/CHANGELOG.md b/packages/image_picker/image_picker_ios/CHANGELOG.md index 0770c429a9f..1e0a897411a 100644 --- a/packages/image_picker/image_picker_ios/CHANGELOG.md +++ b/packages/image_picker/image_picker_ios/CHANGELOG.md @@ -1,3 +1,7 @@ +## NEXT + +* Updates minimum supported SDK version to Flutter 3.29/Dart 3.7. + ## 0.8.13 * Adds support for `getMultiVideoWithOptions`. diff --git a/packages/image_picker/image_picker_ios/example/lib/main.dart b/packages/image_picker/image_picker_ios/example/lib/main.dart index 99a73e99ffe..be547a99b6c 100755 --- a/packages/image_picker/image_picker_ios/example/lib/main.dart +++ b/packages/image_picker/image_picker_ios/example/lib/main.dart @@ -60,8 +60,9 @@ class _MyHomePageState extends State { Future _playVideo(XFile? file) async { if (file != null && mounted) { await _disposeVideoController(); - final VideoPlayerController controller = - VideoPlayerController.file(File(file.path)); + final VideoPlayerController controller = VideoPlayerController.file( + File(file.path), + ); _controller = controller; await controller.setVolume(1.0); await controller.initialize(); @@ -87,7 +88,9 @@ class _MyHomePageState extends State { files = await _picker.getMultiVideoWithOptions(); } else { final XFile? file = await _picker.getVideo( - source: source, maxDuration: const Duration(seconds: 10)); + source: source, + maxDuration: const Duration(seconds: 10), + ); files = [if (file != null) file]; } if (files.isNotEmpty && context.mounted) { @@ -96,28 +99,33 @@ class _MyHomePageState extends State { await _playVideo(files.first); } } else if (allowMultiple) { - await _displayPickImageDialog(context, true, (double? maxWidth, - double? maxHeight, int? quality, int? limit) async { + await _displayPickImageDialog(context, true, ( + double? maxWidth, + double? maxHeight, + int? quality, + int? limit, + ) async { try { final ImageOptions imageOptions = ImageOptions( maxWidth: maxWidth, maxHeight: maxHeight, imageQuality: quality, ); - final List pickedFileList = isMedia - ? await _picker.getMedia( - options: MediaOptions( - allowMultiple: allowMultiple, - imageOptions: imageOptions, - limit: limit, - ), - ) - : await _picker.getMultiImageWithOptions( - options: MultiImagePickerOptions( - imageOptions: imageOptions, - limit: limit, - ), - ); + final List pickedFileList = + isMedia + ? await _picker.getMedia( + options: MediaOptions( + allowMultiple: allowMultiple, + imageOptions: imageOptions, + limit: limit, + ), + ) + : await _picker.getMultiImageWithOptions( + options: MultiImagePickerOptions( + imageOptions: imageOptions, + limit: limit, + ), + ); if (pickedFileList.isNotEmpty && context.mounted) { _showPickedSnackBar(context, pickedFileList); } @@ -131,19 +139,26 @@ class _MyHomePageState extends State { } }); } else if (isMedia) { - await _displayPickImageDialog(context, false, (double? maxWidth, - double? maxHeight, int? quality, int? limit) async { + await _displayPickImageDialog(context, false, ( + double? maxWidth, + double? maxHeight, + int? quality, + int? limit, + ) async { try { final List pickedFileList = []; - final XFile? media = _firstOrNull(await _picker.getMedia( - options: MediaOptions( + final XFile? media = _firstOrNull( + await _picker.getMedia( + options: MediaOptions( allowMultiple: allowMultiple, imageOptions: ImageOptions( maxWidth: maxWidth, maxHeight: maxHeight, imageQuality: quality, - )), - )); + ), + ), + ), + ); if (media != null) { pickedFileList.add(media); @@ -156,8 +171,12 @@ class _MyHomePageState extends State { } }); } else { - await _displayPickImageDialog(context, false, (double? maxWidth, - double? maxHeight, int? quality, int? limit) async { + await _displayPickImageDialog(context, false, ( + double? maxWidth, + double? maxHeight, + int? quality, + int? limit, + ) async { try { final XFile? pickedFile = await _picker.getImageFromSource( source: source, @@ -237,16 +256,21 @@ class _MyHomePageState extends State { final String? mime = lookupMimeType(image.path); return Semantics( label: 'image_picker_example_picked_image', - child: mime == null || mime.startsWith('image/') - ? Image.file( - File(image.path), - errorBuilder: (BuildContext context, Object error, - StackTrace? stackTrace) { - return const Center( - child: Text('This image type is not supported')); - }, - ) - : _buildInlineVideoPlayer(index), + child: + mime == null || mime.startsWith('image/') + ? Image.file( + File(image.path), + errorBuilder: ( + BuildContext context, + Object error, + StackTrace? stackTrace, + ) { + return const Center( + child: Text('This image type is not supported'), + ); + }, + ) + : _buildInlineVideoPlayer(index), ); }, itemCount: _mediaFileList!.length, @@ -266,8 +290,9 @@ class _MyHomePageState extends State { } Widget _buildInlineVideoPlayer(int index) { - final VideoPlayerController controller = - VideoPlayerController.file(File(_mediaFileList![index].path)); + final VideoPlayerController controller = VideoPlayerController.file( + File(_mediaFileList![index].path), + ); controller.setVolume(1.0); controller.initialize(); controller.setLooping(true); @@ -286,13 +311,8 @@ class _MyHomePageState extends State { @override Widget build(BuildContext context) { return Scaffold( - appBar: AppBar( - title: Text(widget.title!), - ), - body: Align( - alignment: Alignment.topCenter, - child: _handlePreview(), - ), + appBar: AppBar(title: Text(widget.title!)), + body: Align(alignment: Alignment.topCenter, child: _handlePreview()), floatingActionButton: Column( mainAxisAlignment: MainAxisAlignment.end, children: [ @@ -395,8 +415,11 @@ class _MyHomePageState extends State { backgroundColor: Colors.red, onPressed: () { _isVideo = true; - _onImageButtonPressed(ImageSource.gallery, - context: context, allowMultiple: true); + _onImageButtonPressed( + ImageSource.gallery, + context: context, + allowMultiple: true, + ); }, heroTag: 'multiVideo', tooltip: 'Pick multiple videos', @@ -433,83 +456,105 @@ class _MyHomePageState extends State { } Future _displayPickImageDialog( - BuildContext context, bool isMulti, OnPickImageCallback onPick) async { + BuildContext context, + bool isMulti, + OnPickImageCallback onPick, + ) async { return showDialog( - context: context, - builder: (BuildContext context) { - return AlertDialog( - title: const Text('Add optional parameters'), - content: Column( - children: [ - TextField( - controller: maxWidthController, - keyboardType: - const TextInputType.numberWithOptions(decimal: true), - decoration: const InputDecoration( - hintText: 'Enter maxWidth if desired'), + context: context, + builder: (BuildContext context) { + return AlertDialog( + title: const Text('Add optional parameters'), + content: Column( + children: [ + TextField( + controller: maxWidthController, + keyboardType: const TextInputType.numberWithOptions( + decimal: true, ), - TextField( - controller: maxHeightController, - keyboardType: - const TextInputType.numberWithOptions(decimal: true), - decoration: const InputDecoration( - hintText: 'Enter maxHeight if desired'), + decoration: const InputDecoration( + hintText: 'Enter maxWidth if desired', + ), + ), + TextField( + controller: maxHeightController, + keyboardType: const TextInputType.numberWithOptions( + decimal: true, ), + decoration: const InputDecoration( + hintText: 'Enter maxHeight if desired', + ), + ), + TextField( + controller: qualityController, + keyboardType: TextInputType.number, + decoration: const InputDecoration( + hintText: 'Enter quality if desired', + ), + ), + if (isMulti) TextField( - controller: qualityController, + controller: limitController, keyboardType: TextInputType.number, decoration: const InputDecoration( - hintText: 'Enter quality if desired'), - ), - if (isMulti) - TextField( - controller: limitController, - keyboardType: TextInputType.number, - decoration: const InputDecoration( - hintText: 'Enter limit if desired'), + hintText: 'Enter limit if desired', ), - ], + ), + ], + ), + actions: [ + TextButton( + child: const Text('CANCEL'), + onPressed: () { + Navigator.of(context).pop(); + }, ), - actions: [ - TextButton( - child: const Text('CANCEL'), - onPressed: () { - Navigator.of(context).pop(); - }, - ), - TextButton( - child: const Text('PICK'), - onPressed: () { - final double? width = maxWidthController.text.isNotEmpty + TextButton( + child: const Text('PICK'), + onPressed: () { + final double? width = + maxWidthController.text.isNotEmpty ? double.parse(maxWidthController.text) : null; - final double? height = maxHeightController.text.isNotEmpty + final double? height = + maxHeightController.text.isNotEmpty ? double.parse(maxHeightController.text) : null; - final int? quality = qualityController.text.isNotEmpty + final int? quality = + qualityController.text.isNotEmpty ? int.parse(qualityController.text) : null; - final int? limit = limitController.text.isNotEmpty + final int? limit = + limitController.text.isNotEmpty ? int.parse(limitController.text) : null; - onPick(width, height, quality, limit); - Navigator.of(context).pop(); - }), - ], - ); - }); + onPick(width, height, quality, limit); + Navigator.of(context).pop(); + }, + ), + ], + ); + }, + ); } void _showPickedSnackBar(BuildContext context, List files) { - ScaffoldMessenger.of(context).showSnackBar(SnackBar( - content: Text('Picked: ${files.map((XFile it) => it.name).join(',')}'), - duration: const Duration(seconds: 2), - )); + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text('Picked: ${files.map((XFile it) => it.name).join(',')}'), + duration: const Duration(seconds: 2), + ), + ); } } -typedef OnPickImageCallback = void Function( - double? maxWidth, double? maxHeight, int? quality, int? limit); +typedef OnPickImageCallback = + void Function( + double? maxWidth, + double? maxHeight, + int? quality, + int? limit, + ); class AspectRatioVideo extends StatefulWidget { const AspectRatioVideo(this.controller, {super.key}); diff --git a/packages/image_picker/image_picker_ios/example/pubspec.yaml b/packages/image_picker/image_picker_ios/example/pubspec.yaml index 1d1c431aa68..ea46de1cc7e 100755 --- a/packages/image_picker/image_picker_ios/example/pubspec.yaml +++ b/packages/image_picker/image_picker_ios/example/pubspec.yaml @@ -3,8 +3,8 @@ description: Demonstrates how to use the image_picker plugin. publish_to: none environment: - sdk: ^3.6.0 - flutter: ">=3.27.0" + sdk: ^3.7.0 + flutter: ">=3.29.0" dependencies: flutter: 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 ee9243fc000..0bdcf49023a 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 @@ -120,7 +120,10 @@ class ImagePickerIOS extends ImagePickerPlatform { final int? imageQuality = options.imageOptions.imageQuality; if (imageQuality != null && (imageQuality < 0 || imageQuality > 100)) { throw ArgumentError.value( - imageQuality, 'imageQuality', 'must be between 0 and 100'); + imageQuality, + 'imageQuality', + 'must be between 0 and 100', + ); } final double? maxWidth = options.imageOptions.maxWidth; @@ -153,7 +156,10 @@ class ImagePickerIOS extends ImagePickerPlatform { final int? imageQuality = options.imageQuality; if (imageQuality != null && (imageQuality < 0 || imageQuality > 100)) { throw ArgumentError.value( - imageQuality, 'imageQuality', 'must be between 0 and 100'); + imageQuality, + 'imageQuality', + 'must be between 0 and 100', + ); } final double? maxHeight = options.maxHeight; @@ -178,15 +184,13 @@ class ImagePickerIOS extends ImagePickerPlatform { } @override - Future> getMedia({ - required MediaOptions options, - }) async { + Future> getMedia({required MediaOptions options}) async { final MediaSelectionOptions mediaSelectionOptions = _mediaOptionsToMediaSelectionOptions(options); - return (await _hostApi.pickMedia(mediaSelectionOptions)) - .map((String? path) => XFile(path!)) - .toList(); + return (await _hostApi.pickMedia( + mediaSelectionOptions, + )).map((String? path) => XFile(path!)).toList(); } MaxSize _imageOptionsToMaxSizeWithValidation(ImageOptions imageOptions) { @@ -196,7 +200,10 @@ class ImagePickerIOS extends ImagePickerPlatform { if (imageQuality != null && (imageQuality < 0 || imageQuality > 100)) { throw ArgumentError.value( - imageQuality, 'imageQuality', 'must be between 0 and 100'); + imageQuality, + 'imageQuality', + 'must be between 0 and 100', + ); } if (maxWidth != null && maxWidth < 0) { @@ -211,9 +218,11 @@ class ImagePickerIOS extends ImagePickerPlatform { } MediaSelectionOptions _mediaOptionsToMediaSelectionOptions( - MediaOptions mediaOptions) { - final MaxSize maxSize = - _imageOptionsToMaxSizeWithValidation(mediaOptions.imageOptions); + MediaOptions mediaOptions, + ) { + final MaxSize maxSize = _imageOptionsToMaxSizeWithValidation( + mediaOptions.imageOptions, + ); final bool allowMultiple = mediaOptions.allowMultiple; final int? limit = mediaOptions.limit; @@ -259,10 +268,12 @@ class ImagePickerIOS extends ImagePickerPlatform { Duration? maxDuration, }) { return _hostApi.pickVideo( - SourceSpecification( - type: _convertSource(source), - camera: _convertCamera(preferredCameraDevice)), - maxDuration?.inSeconds); + SourceSpecification( + type: _convertSource(source), + camera: _convertCamera(preferredCameraDevice), + ), + maxDuration?.inSeconds, + ); } @override @@ -328,8 +339,8 @@ class ImagePickerIOS extends ImagePickerPlatform { MultiVideoPickerOptions options = const MultiVideoPickerOptions(), }) async { return (await _hostApi.pickMultiVideo( - options.maxDuration?.inSeconds, options.limit)) - .map((String path) => XFile(path)) - .toList(); + options.maxDuration?.inSeconds, + options.limit, + )).map((String path) => XFile(path)).toList(); } } diff --git a/packages/image_picker/image_picker_ios/lib/src/messages.g.dart b/packages/image_picker/image_picker_ios/lib/src/messages.g.dart index 14112c77c44..4e305913060 100644 --- a/packages/image_picker/image_picker_ios/lib/src/messages.g.dart +++ b/packages/image_picker/image_picker_ios/lib/src/messages.g.dart @@ -18,8 +18,11 @@ PlatformException _createConnectionError(String channelName) { ); } -List wrapResponse( - {Object? result, PlatformException? error, bool empty = false}) { +List wrapResponse({ + Object? result, + PlatformException? error, + bool empty = false, +}) { if (empty) { return []; } @@ -29,39 +32,24 @@ List wrapResponse( return [error.code, error.message, error.details]; } -enum SourceCamera { - rear, - front, -} +enum SourceCamera { rear, front } -enum SourceType { - camera, - gallery, -} +enum SourceType { camera, gallery } class MaxSize { - MaxSize({ - this.width, - this.height, - }); + MaxSize({this.width, this.height}); double? width; double? height; Object encode() { - return [ - width, - height, - ]; + return [width, height]; } static MaxSize decode(Object result) { result as List; - return MaxSize( - width: result[0] as double?, - height: result[1] as double?, - ); + return MaxSize(width: result[0] as double?, height: result[1] as double?); } } @@ -107,20 +95,14 @@ class MediaSelectionOptions { } class SourceSpecification { - SourceSpecification({ - required this.type, - required this.camera, - }); + SourceSpecification({required this.type, required this.camera}); SourceType type; SourceCamera camera; Object encode() { - return [ - type, - camera, - ]; + return [type, camera]; } static SourceSpecification decode(Object result) { @@ -184,30 +166,40 @@ class ImagePickerApi { /// Constructor for [ImagePickerApi]. The [binaryMessenger] named argument is /// available for dependency injection. If it is left null, the default /// BinaryMessenger will be used which routes to the host platform. - ImagePickerApi( - {BinaryMessenger? binaryMessenger, String messageChannelSuffix = ''}) - : pigeonVar_binaryMessenger = binaryMessenger, - pigeonVar_messageChannelSuffix = - messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; + ImagePickerApi({ + BinaryMessenger? binaryMessenger, + String messageChannelSuffix = '', + }) : pigeonVar_binaryMessenger = binaryMessenger, + pigeonVar_messageChannelSuffix = + messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; final BinaryMessenger? pigeonVar_binaryMessenger; static const MessageCodec pigeonChannelCodec = _PigeonCodec(); final String pigeonVar_messageChannelSuffix; - Future pickImage(SourceSpecification source, MaxSize maxSize, - int? imageQuality, bool requestFullMetadata) async { + Future pickImage( + SourceSpecification source, + MaxSize maxSize, + int? imageQuality, + bool requestFullMetadata, + ) async { final String pigeonVar_channelName = 'dev.flutter.pigeon.image_picker_ios.ImagePickerApi.pickImage$pigeonVar_messageChannelSuffix'; final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - pigeonVar_channelName, - pigeonChannelCodec, - binaryMessenger: pigeonVar_binaryMessenger, - ); - final List? pigeonVar_replyList = await pigeonVar_channel - .send([source, maxSize, imageQuality, requestFullMetadata]) - as List?; + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([ + source, + maxSize, + imageQuality, + requestFullMetadata, + ]) + as List?; if (pigeonVar_replyList == null) { throw _createConnectionError(pigeonVar_channelName); } else if (pigeonVar_replyList.length > 1) { @@ -221,19 +213,28 @@ class ImagePickerApi { } } - Future> pickMultiImage(MaxSize maxSize, int? imageQuality, - bool requestFullMetadata, int? limit) async { + Future> pickMultiImage( + MaxSize maxSize, + int? imageQuality, + bool requestFullMetadata, + int? limit, + ) async { final String pigeonVar_channelName = 'dev.flutter.pigeon.image_picker_ios.ImagePickerApi.pickMultiImage$pigeonVar_messageChannelSuffix'; final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - pigeonVar_channelName, - pigeonChannelCodec, - binaryMessenger: pigeonVar_binaryMessenger, - ); - final List? pigeonVar_replyList = await pigeonVar_channel - .send([maxSize, imageQuality, requestFullMetadata, limit]) - as List?; + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([ + maxSize, + imageQuality, + requestFullMetadata, + limit, + ]) + as List?; if (pigeonVar_replyList == null) { throw _createConnectionError(pigeonVar_channelName); } else if (pigeonVar_replyList.length > 1) { @@ -253,17 +254,20 @@ class ImagePickerApi { } Future pickVideo( - SourceSpecification source, int? maxDurationSeconds) async { + SourceSpecification source, + int? maxDurationSeconds, + ) async { final String pigeonVar_channelName = 'dev.flutter.pigeon.image_picker_ios.ImagePickerApi.pickVideo$pigeonVar_messageChannelSuffix'; final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - pigeonVar_channelName, - pigeonChannelCodec, - binaryMessenger: pigeonVar_binaryMessenger, - ); - final List? pigeonVar_replyList = await pigeonVar_channel - .send([source, maxDurationSeconds]) as List?; + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([source, maxDurationSeconds]) + as List?; if (pigeonVar_replyList == null) { throw _createConnectionError(pigeonVar_channelName); } else if (pigeonVar_replyList.length > 1) { @@ -278,17 +282,20 @@ class ImagePickerApi { } Future> pickMultiVideo( - int? maxDurationSeconds, int? limit) async { + int? maxDurationSeconds, + int? limit, + ) async { final String pigeonVar_channelName = 'dev.flutter.pigeon.image_picker_ios.ImagePickerApi.pickMultiVideo$pigeonVar_messageChannelSuffix'; final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - pigeonVar_channelName, - pigeonChannelCodec, - binaryMessenger: pigeonVar_binaryMessenger, - ); - final List? pigeonVar_replyList = await pigeonVar_channel - .send([maxDurationSeconds, limit]) as List?; + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([maxDurationSeconds, limit]) + as List?; if (pigeonVar_replyList == null) { throw _createConnectionError(pigeonVar_channelName); } else if (pigeonVar_replyList.length > 1) { @@ -309,17 +316,19 @@ class ImagePickerApi { /// Selects images and videos and returns their paths. Future> pickMedia( - MediaSelectionOptions mediaSelectionOptions) async { + MediaSelectionOptions mediaSelectionOptions, + ) async { final String pigeonVar_channelName = 'dev.flutter.pigeon.image_picker_ios.ImagePickerApi.pickMedia$pigeonVar_messageChannelSuffix'; final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - pigeonVar_channelName, - pigeonChannelCodec, - binaryMessenger: pigeonVar_binaryMessenger, - ); - final List? pigeonVar_replyList = await pigeonVar_channel - .send([mediaSelectionOptions]) as List?; + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([mediaSelectionOptions]) + as List?; if (pigeonVar_replyList == null) { throw _createConnectionError(pigeonVar_channelName); } else if (pigeonVar_replyList.length > 1) { diff --git a/packages/image_picker/image_picker_ios/pigeons/messages.dart b/packages/image_picker/image_picker_ios/pigeons/messages.dart index 45b98c2bcf2..aad06f10359 100644 --- a/packages/image_picker/image_picker_ios/pigeons/messages.dart +++ b/packages/image_picker/image_picker_ios/pigeons/messages.dart @@ -4,18 +4,20 @@ 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', - objcOptions: ObjcOptions( - prefix: 'FLT', - headerIncludePath: './include/image_picker_ios/messages.g.h', +@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', + objcOptions: ObjcOptions( + prefix: 'FLT', + headerIncludePath: './include/image_picker_ios/messages.g.h', + ), + copyrightHeader: 'pigeons/copyright.txt', ), - copyrightHeader: 'pigeons/copyright.txt', -)) +) class MaxSize { MaxSize(this.width, this.height); double? width; @@ -54,12 +56,20 @@ class SourceSpecification { abstract class ImagePickerApi { @async @ObjCSelector('pickImageWithSource:maxSize:quality:fullMetadata:') - String? pickImage(SourceSpecification source, MaxSize maxSize, - int? imageQuality, bool requestFullMetadata); + String? pickImage( + SourceSpecification source, + MaxSize maxSize, + int? imageQuality, + bool requestFullMetadata, + ); @async @ObjCSelector('pickMultiImageWithMaxSize:quality:fullMetadata:limit:') List pickMultiImage( - MaxSize maxSize, int? imageQuality, bool requestFullMetadata, int? limit); + MaxSize maxSize, + int? imageQuality, + bool requestFullMetadata, + int? limit, + ); @async @ObjCSelector('pickVideoWithSource:maxDuration:') String? pickVideo(SourceSpecification source, int? maxDurationSeconds); diff --git a/packages/image_picker/image_picker_ios/pubspec.yaml b/packages/image_picker/image_picker_ios/pubspec.yaml index 84b8d372b1f..e153b3bbbfe 100755 --- a/packages/image_picker/image_picker_ios/pubspec.yaml +++ b/packages/image_picker/image_picker_ios/pubspec.yaml @@ -5,8 +5,8 @@ issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+ version: 0.8.13 environment: - sdk: ^3.6.0 - flutter: ">=3.27.0" + sdk: ^3.7.0 + flutter: ">=3.29.0" flutter: plugin: 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 c9eb37415ab..bc00356807a 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 @@ -45,14 +45,19 @@ class _ApiLogger implements TestHostImagePickerApi { 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, - })); + 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?; } @@ -63,48 +68,73 @@ class _ApiLogger implements TestHostImagePickerApi { bool requestFullMetadata, int? limit, ) async { - calls.add(_LoggedMethodCall('pickMultiImage', arguments: { - 'maxWidth': maxSize.width, - 'maxHeight': maxSize.height, - 'imageQuality': imageQuality, - 'requestFullMetadata': requestFullMetadata, - 'limit': limit, - })); + 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, - })); + 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, - })); + 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, - })); + int? maxDurationSeconds, + int? limit, + ) async { + calls.add( + _LoggedMethodCall( + 'pickMultiVideo', + arguments: { + 'maxDuration': maxDurationSeconds, + 'limit': limit, + }, + ), + ); return returnValue as List; } } @@ -130,39 +160,36 @@ void main() { await picker.pickImage(source: ImageSource.camera); await picker.pickImage(source: ImageSource.gallery); - expect( - log.calls, - <_LoggedMethodCall>[ - const _LoggedMethodCall('pickImage', arguments: { + 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: { + }, + ), + const _LoggedMethodCall( + 'pickImage', + arguments: { 'source': SourceType.gallery, 'maxWidth': null, 'maxHeight': null, 'imageQuality': null, 'cameraDevice': SourceCamera.rear, 'requestFullMetadata': true, - }), - ], - ); + }, + ), + ]); }); 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, - ); + await picker.pickImage(source: ImageSource.camera, maxWidth: 10.0); + await picker.pickImage(source: ImageSource.camera, maxHeight: 10.0); await picker.pickImage( source: ImageSource.camera, maxWidth: 10.0, @@ -185,67 +212,85 @@ void main() { imageQuality: 70, ); - expect( - log.calls, - <_LoggedMethodCall>[ - const _LoggedMethodCall('pickImage', arguments: { + 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: { + }, + ), + const _LoggedMethodCall( + 'pickImage', + arguments: { 'source': SourceType.camera, 'maxWidth': 10.0, 'maxHeight': null, 'imageQuality': null, 'cameraDevice': SourceCamera.rear, 'requestFullMetadata': true, - }), - const _LoggedMethodCall('pickImage', arguments: { + }, + ), + const _LoggedMethodCall( + 'pickImage', + arguments: { 'source': SourceType.camera, 'maxWidth': null, 'maxHeight': 10.0, 'imageQuality': null, 'cameraDevice': SourceCamera.rear, 'requestFullMetadata': true, - }), - const _LoggedMethodCall('pickImage', arguments: { + }, + ), + const _LoggedMethodCall( + 'pickImage', + arguments: { 'source': SourceType.camera, 'maxWidth': 10.0, 'maxHeight': 20.0, 'imageQuality': null, 'cameraDevice': SourceCamera.rear, 'requestFullMetadata': true, - }), - const _LoggedMethodCall('pickImage', arguments: { + }, + ), + const _LoggedMethodCall( + 'pickImage', + arguments: { 'source': SourceType.camera, 'maxWidth': 10.0, 'maxHeight': null, 'imageQuality': 70, 'cameraDevice': SourceCamera.rear, 'requestFullMetadata': true, - }), - const _LoggedMethodCall('pickImage', arguments: { + }, + ), + const _LoggedMethodCall( + 'pickImage', + arguments: { 'source': SourceType.camera, 'maxWidth': null, 'maxHeight': 10.0, 'imageQuality': 70, 'cameraDevice': SourceCamera.rear, 'requestFullMetadata': true, - }), - const _LoggedMethodCall('pickImage', arguments: { + }, + ), + const _LoggedMethodCall( + 'pickImage', + arguments: { 'source': SourceType.camera, 'maxWidth': 10.0, 'maxHeight': 20.0, 'imageQuality': 70, 'cameraDevice': SourceCamera.rear, 'requestFullMetadata': true, - }), - ], - ); + }, + ), + ]); }); test('does not accept a invalid imageQuality argument', () { @@ -292,39 +337,40 @@ void main() { test('camera position defaults to back', () async { await picker.pickImage(source: ImageSource.camera); - expect( - log.calls, - <_LoggedMethodCall>[ - const _LoggedMethodCall('pickImage', arguments: { + 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 { await picker.pickImage( - source: ImageSource.camera, - preferredCameraDevice: CameraDevice.front); + source: ImageSource.camera, + preferredCameraDevice: CameraDevice.front, + ); - expect( - log.calls, - <_LoggedMethodCall>[ - const _LoggedMethodCall('pickImage', arguments: { + expect(log.calls, <_LoggedMethodCall>[ + const _LoggedMethodCall( + 'pickImage', + arguments: { 'source': SourceType.camera, 'maxWidth': null, 'maxHeight': null, 'imageQuality': null, 'cameraDevice': SourceCamera.front, 'requestFullMetadata': true, - }), - ], - ); + }, + ), + ]); }); }); @@ -333,121 +379,112 @@ void main() { 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, - }), - ], - ); + expect(log.calls, <_LoggedMethodCall>[ + const _LoggedMethodCall( + 'pickMultiImage', + arguments: { + 'maxWidth': null, + 'maxHeight': null, + 'imageQuality': null, + 'requestFullMetadata': true, + 'limit': 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); + 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(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, + }, + ), + ]); }); test('does not accept a negative width or height argument', () { - expect( - () => picker.pickMultiImage(maxWidth: -1.0), - throwsArgumentError, - ); + expect(() => picker.pickMultiImage(maxWidth: -1.0), throwsArgumentError); - expect( - () => picker.pickMultiImage(maxHeight: -1.0), - throwsArgumentError, - ); + expect(() => picker.pickMultiImage(maxHeight: -1.0), throwsArgumentError); }); test('does not accept a invalid imageQuality argument', () { @@ -474,21 +511,24 @@ void main() { await picker.pickVideo(source: ImageSource.camera); await picker.pickVideo(source: ImageSource.gallery); - expect( - log.calls, - <_LoggedMethodCall>[ - const _LoggedMethodCall('pickVideo', arguments: { + expect(log.calls, <_LoggedMethodCall>[ + const _LoggedMethodCall( + 'pickVideo', + arguments: { 'source': SourceType.camera, 'cameraDevice': SourceCamera.rear, 'maxDuration': null, - }), - const _LoggedMethodCall('pickVideo', arguments: { + }, + ), + const _LoggedMethodCall( + 'pickVideo', + arguments: { 'source': SourceType.gallery, 'cameraDevice': SourceCamera.rear, 'maxDuration': null, - }), - ], - ); + }, + ), + ]); }); test('passes the duration argument correctly', () async { @@ -505,31 +545,40 @@ void main() { source: ImageSource.camera, maxDuration: const Duration(hours: 1), ); - expect( - log.calls, - <_LoggedMethodCall>[ - const _LoggedMethodCall('pickVideo', arguments: { + expect(log.calls, <_LoggedMethodCall>[ + const _LoggedMethodCall( + 'pickVideo', + arguments: { 'source': SourceType.camera, 'maxDuration': null, 'cameraDevice': SourceCamera.rear, - }), - const _LoggedMethodCall('pickVideo', arguments: { + }, + ), + const _LoggedMethodCall( + 'pickVideo', + arguments: { 'source': SourceType.camera, 'maxDuration': 10, 'cameraDevice': SourceCamera.rear, - }), - const _LoggedMethodCall('pickVideo', arguments: { + }, + ), + const _LoggedMethodCall( + 'pickVideo', + arguments: { 'source': SourceType.camera, 'maxDuration': 60, 'cameraDevice': SourceCamera.rear, - }), - const _LoggedMethodCall('pickVideo', arguments: { + }, + ), + const _LoggedMethodCall( + 'pickVideo', + arguments: { 'source': SourceType.camera, 'maxDuration': 3600, 'cameraDevice': SourceCamera.rear, - }), - ], - ); + }, + ), + ]); }); test('handles a null video path response gracefully', () async { @@ -542,16 +591,16 @@ void main() { test('camera position defaults to back', () async { await picker.pickVideo(source: ImageSource.camera); - expect( - log.calls, - <_LoggedMethodCall>[ - const _LoggedMethodCall('pickVideo', arguments: { + expect(log.calls, <_LoggedMethodCall>[ + const _LoggedMethodCall( + 'pickVideo', + arguments: { 'source': SourceType.camera, 'cameraDevice': SourceCamera.rear, 'maxDuration': null, - }), - ], - ); + }, + ), + ]); }); test('camera position can set to front', () async { @@ -560,16 +609,16 @@ void main() { preferredCameraDevice: CameraDevice.front, ); - expect( - log.calls, - <_LoggedMethodCall>[ - const _LoggedMethodCall('pickVideo', arguments: { + expect(log.calls, <_LoggedMethodCall>[ + const _LoggedMethodCall( + 'pickVideo', + arguments: { 'source': SourceType.camera, 'maxDuration': null, 'cameraDevice': SourceCamera.front, - }), - ], - ); + }, + ), + ]); }); }); @@ -578,39 +627,36 @@ void main() { await picker.getImage(source: ImageSource.camera); await picker.getImage(source: ImageSource.gallery); - expect( - log.calls, - <_LoggedMethodCall>[ - const _LoggedMethodCall('pickImage', arguments: { + 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: { + }, + ), + const _LoggedMethodCall( + 'pickImage', + arguments: { 'source': SourceType.gallery, 'maxWidth': null, 'maxHeight': null, 'imageQuality': null, 'cameraDevice': SourceCamera.rear, 'requestFullMetadata': true, - }), - ], - ); + }, + ), + ]); }); 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); + await picker.getImage(source: ImageSource.camera, maxHeight: 10.0); await picker.getImage( source: ImageSource.camera, maxWidth: 10.0, @@ -633,67 +679,85 @@ void main() { imageQuality: 70, ); - expect( - log.calls, - <_LoggedMethodCall>[ - const _LoggedMethodCall('pickImage', arguments: { + 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: { + }, + ), + const _LoggedMethodCall( + 'pickImage', + arguments: { 'source': SourceType.camera, 'maxWidth': 10.0, 'maxHeight': null, 'imageQuality': null, 'cameraDevice': SourceCamera.rear, 'requestFullMetadata': true, - }), - const _LoggedMethodCall('pickImage', arguments: { + }, + ), + const _LoggedMethodCall( + 'pickImage', + arguments: { 'source': SourceType.camera, 'maxWidth': null, 'maxHeight': 10.0, 'imageQuality': null, 'cameraDevice': SourceCamera.rear, 'requestFullMetadata': true, - }), - const _LoggedMethodCall('pickImage', arguments: { + }, + ), + const _LoggedMethodCall( + 'pickImage', + arguments: { 'source': SourceType.camera, 'maxWidth': 10.0, 'maxHeight': 20.0, 'imageQuality': null, 'cameraDevice': SourceCamera.rear, 'requestFullMetadata': true, - }), - const _LoggedMethodCall('pickImage', arguments: { + }, + ), + const _LoggedMethodCall( + 'pickImage', + arguments: { 'source': SourceType.camera, 'maxWidth': 10.0, 'maxHeight': null, 'imageQuality': 70, 'cameraDevice': SourceCamera.rear, 'requestFullMetadata': true, - }), - const _LoggedMethodCall('pickImage', arguments: { + }, + ), + const _LoggedMethodCall( + 'pickImage', + arguments: { 'source': SourceType.camera, 'maxWidth': null, 'maxHeight': 10.0, 'imageQuality': 70, 'cameraDevice': SourceCamera.rear, 'requestFullMetadata': true, - }), - const _LoggedMethodCall('pickImage', arguments: { + }, + ), + const _LoggedMethodCall( + 'pickImage', + arguments: { 'source': SourceType.camera, 'maxWidth': 10.0, 'maxHeight': 20.0, 'imageQuality': 70, 'cameraDevice': SourceCamera.rear, 'requestFullMetadata': true, - }), - ], - ); + }, + ), + ]); }); test('does not accept a invalid imageQuality argument', () { @@ -740,39 +804,40 @@ void main() { test('camera position defaults to back', () async { await picker.getImage(source: ImageSource.camera); - expect( - log.calls, - <_LoggedMethodCall>[ - const _LoggedMethodCall('pickImage', arguments: { + 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 { await picker.getImage( - source: ImageSource.camera, - preferredCameraDevice: CameraDevice.front); + source: ImageSource.camera, + preferredCameraDevice: CameraDevice.front, + ); - expect( - log.calls, - <_LoggedMethodCall>[ - const _LoggedMethodCall('pickImage', arguments: { + expect(log.calls, <_LoggedMethodCall>[ + const _LoggedMethodCall( + 'pickImage', + arguments: { 'source': SourceType.camera, 'maxWidth': null, 'maxHeight': null, 'imageQuality': null, 'cameraDevice': SourceCamera.front, 'requestFullMetadata': true, - }), - ], - ); + }, + ), + ]); }); }); @@ -781,130 +846,118 @@ void main() { 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, - }), - ], - ); + expect(log.calls, <_LoggedMethodCall>[ + const _LoggedMethodCall( + 'pickMultiImage', + arguments: { + 'maxWidth': null, + 'maxHeight': null, + 'imageQuality': null, + 'requestFullMetadata': true, + 'limit': 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); + 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(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, + }, + ), + ]); }); test('does not accept a negative width or height argument', () { log.returnValue = ['0', '1']; - expect( - () => picker.getMultiImage(maxWidth: -1.0), - throwsArgumentError, - ); + expect(() => picker.getMultiImage(maxWidth: -1.0), throwsArgumentError); - expect( - () => picker.getMultiImage(maxHeight: -1.0), - throwsArgumentError, - ); + expect(() => picker.getMultiImage(maxHeight: -1.0), throwsArgumentError); }); test('does not accept a invalid imageQuality argument', () { log.returnValue = ['0', '1']; - expect( - () => picker.getMultiImage(imageQuality: -1), - throwsArgumentError, - ); + expect(() => picker.getMultiImage(imageQuality: -1), throwsArgumentError); expect( () => picker.getMultiImage(imageQuality: 101), @@ -924,215 +977,239 @@ void main() { log.returnValue = ['0', '1']; await picker.getMedia(options: const MediaOptions(allowMultiple: true)); - expect( - log.calls, - <_LoggedMethodCall>[ - const _LoggedMethodCall('pickMedia', arguments: { + expect(log.calls, <_LoggedMethodCall>[ + const _LoggedMethodCall( + 'pickMedia', + arguments: { 'maxWidth': null, 'maxHeight': null, 'imageQuality': null, 'requestFullMetadata': true, 'allowMultiple': true, '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, + options: MediaOptions( + allowMultiple: true, + imageOptions: ImageOptions.createAndValidate(maxWidth: 10.0), ), - )); + ); await picker.getMedia( - options: MediaOptions( - allowMultiple: true, - imageOptions: ImageOptions.createAndValidate( - maxHeight: 10.0, + options: MediaOptions( + allowMultiple: true, + imageOptions: ImageOptions.createAndValidate(maxHeight: 10.0), ), - )); + ); await picker.getMedia( - options: MediaOptions( - allowMultiple: true, - imageOptions: ImageOptions.createAndValidate( - maxWidth: 10.0, - maxHeight: 20.0, + options: MediaOptions( + allowMultiple: true, + imageOptions: ImageOptions.createAndValidate( + maxWidth: 10.0, + maxHeight: 20.0, + ), ), - )); + ); await picker.getMedia( - options: MediaOptions( - allowMultiple: true, - imageOptions: ImageOptions.createAndValidate( - maxWidth: 10.0, - imageQuality: 70, + 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, + 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, + 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, + options: MediaOptions( + allowMultiple: true, + imageOptions: ImageOptions.createAndValidate( + maxWidth: 10.0, + maxHeight: 20.0, + imageQuality: 70, + ), + limit: 5, ), - limit: 5, - )); + ); - expect( - log.calls, - <_LoggedMethodCall>[ - const _LoggedMethodCall('pickMedia', arguments: { + expect(log.calls, <_LoggedMethodCall>[ + const _LoggedMethodCall( + 'pickMedia', + arguments: { 'maxWidth': null, 'maxHeight': null, 'imageQuality': null, 'requestFullMetadata': true, 'allowMultiple': true, 'limit': null, - }), - const _LoggedMethodCall('pickMedia', arguments: { + }, + ), + const _LoggedMethodCall( + 'pickMedia', + arguments: { 'maxWidth': 10.0, 'maxHeight': null, 'imageQuality': null, 'requestFullMetadata': true, 'allowMultiple': true, 'limit': null, - }), - const _LoggedMethodCall('pickMedia', arguments: { + }, + ), + const _LoggedMethodCall( + 'pickMedia', + arguments: { 'maxWidth': null, 'maxHeight': 10.0, 'imageQuality': null, 'requestFullMetadata': true, 'allowMultiple': true, 'limit': null, - }), - const _LoggedMethodCall('pickMedia', arguments: { + }, + ), + const _LoggedMethodCall( + 'pickMedia', + arguments: { 'maxWidth': 10.0, 'maxHeight': 20.0, 'imageQuality': null, 'requestFullMetadata': true, 'allowMultiple': true, 'limit': null, - }), - const _LoggedMethodCall('pickMedia', arguments: { + }, + ), + const _LoggedMethodCall( + 'pickMedia', + arguments: { 'maxWidth': 10.0, 'maxHeight': null, 'imageQuality': 70, 'requestFullMetadata': true, 'allowMultiple': true, 'limit': null, - }), - const _LoggedMethodCall('pickMedia', arguments: { + }, + ), + const _LoggedMethodCall( + 'pickMedia', + arguments: { 'maxWidth': null, 'maxHeight': 10.0, 'imageQuality': 70, 'requestFullMetadata': true, 'allowMultiple': true, 'limit': null, - }), - const _LoggedMethodCall('pickMedia', arguments: { + }, + ), + const _LoggedMethodCall( + 'pickMedia', + arguments: { 'maxWidth': 10.0, 'maxHeight': 20.0, 'imageQuality': 70, 'requestFullMetadata': true, 'allowMultiple': true, 'limit': null, - }), - const _LoggedMethodCall('pickMedia', arguments: { + }, + ), + const _LoggedMethodCall( + 'pickMedia', + arguments: { 'maxWidth': 10.0, 'maxHeight': 20.0, 'imageQuality': 70, 'requestFullMetadata': true, 'allowMultiple': true, 'limit': 5, - }), - ], - ); + }, + ), + ]); }); test('passes request metadata argument correctly', () async { log.returnValue = ['0', '1']; await picker.getMedia( - options: const MediaOptions( - allowMultiple: true, - imageOptions: ImageOptions(requestFullMetadata: false), - )); + options: const MediaOptions( + allowMultiple: true, + imageOptions: ImageOptions(requestFullMetadata: false), + ), + ); - expect( - log.calls, - <_LoggedMethodCall>[ - const _LoggedMethodCall('pickMedia', arguments: { + expect(log.calls, <_LoggedMethodCall>[ + const _LoggedMethodCall( + 'pickMedia', + arguments: { 'maxWidth': null, 'maxHeight': null, 'imageQuality': null, 'requestFullMetadata': false, 'allowMultiple': true, 'limit': null, - }), - ], - ); + }, + ), + ]); }); test('passes allowMultiple argument correctly', () async { log.returnValue = ['0', '1']; - await picker.getMedia( - options: const MediaOptions( - allowMultiple: false, - )); + await picker.getMedia(options: const MediaOptions(allowMultiple: false)); - expect( - log.calls, - <_LoggedMethodCall>[ - const _LoggedMethodCall('pickMedia', arguments: { + expect(log.calls, <_LoggedMethodCall>[ + const _LoggedMethodCall( + 'pickMedia', + arguments: { 'maxWidth': null, 'maxHeight': null, 'imageQuality': null, 'requestFullMetadata': true, 'allowMultiple': false, 'limit': null, - }), - ], - ); + }, + ), + ]); }); test('does not accept a negative width or height argument', () { log.returnValue = ['0', '1']; expect( () => picker.getMedia( - options: MediaOptions( - allowMultiple: true, - imageOptions: ImageOptions.createAndValidate(maxWidth: -1.0), - )), + options: MediaOptions( + allowMultiple: true, + imageOptions: ImageOptions.createAndValidate(maxWidth: -1.0), + ), + ), throwsArgumentError, ); expect( () => picker.getMedia( - options: MediaOptions( - allowMultiple: true, - imageOptions: ImageOptions.createAndValidate(maxHeight: -1.0), - )), + options: MediaOptions( + allowMultiple: true, + imageOptions: ImageOptions.createAndValidate(maxHeight: -1.0), + ), + ), throwsArgumentError, ); }); @@ -1141,19 +1218,21 @@ void main() { log.returnValue = ['0', '1']; expect( () => picker.getMedia( - options: MediaOptions( - allowMultiple: true, - imageOptions: ImageOptions.createAndValidate(imageQuality: -1), - )), + options: MediaOptions( + allowMultiple: true, + imageOptions: ImageOptions.createAndValidate(imageQuality: -1), + ), + ), throwsArgumentError, ); expect( () => picker.getMedia( - options: MediaOptions( - allowMultiple: true, - imageOptions: ImageOptions.createAndValidate(imageQuality: 101), - )), + options: MediaOptions( + allowMultiple: true, + imageOptions: ImageOptions.createAndValidate(imageQuality: 101), + ), + ), throwsArgumentError, ); }); @@ -1162,19 +1241,15 @@ void main() { log.returnValue = ['0', '1']; expect( () => picker.getMedia( - options: const MediaOptions( - allowMultiple: true, - limit: -1, - )), + options: const MediaOptions(allowMultiple: true, limit: -1), + ), throwsArgumentError, ); expect( () => picker.getMedia( - options: const MediaOptions( - allowMultiple: true, - limit: 0, - )), + options: const MediaOptions(allowMultiple: true, limit: 0), + ), throwsArgumentError, ); }); @@ -1192,9 +1267,9 @@ void main() { log.returnValue = []; expect( - await picker.getMedia( - options: const MediaOptions(allowMultiple: true)), - []); + await picker.getMedia(options: const MediaOptions(allowMultiple: true)), + [], + ); }); }); @@ -1203,21 +1278,24 @@ void main() { await picker.getVideo(source: ImageSource.camera); await picker.getVideo(source: ImageSource.gallery); - expect( - log.calls, - <_LoggedMethodCall>[ - const _LoggedMethodCall('pickVideo', arguments: { + expect(log.calls, <_LoggedMethodCall>[ + const _LoggedMethodCall( + 'pickVideo', + arguments: { 'source': SourceType.camera, 'cameraDevice': SourceCamera.rear, 'maxDuration': null, - }), - const _LoggedMethodCall('pickVideo', arguments: { + }, + ), + const _LoggedMethodCall( + 'pickVideo', + arguments: { 'source': SourceType.gallery, 'cameraDevice': SourceCamera.rear, 'maxDuration': null, - }), - ], - ); + }, + ), + ]); }); test('passes the duration argument correctly', () async { @@ -1234,31 +1312,40 @@ void main() { source: ImageSource.camera, maxDuration: const Duration(hours: 1), ); - expect( - log.calls, - <_LoggedMethodCall>[ - const _LoggedMethodCall('pickVideo', arguments: { + expect(log.calls, <_LoggedMethodCall>[ + const _LoggedMethodCall( + 'pickVideo', + arguments: { 'source': SourceType.camera, 'maxDuration': null, 'cameraDevice': SourceCamera.rear, - }), - const _LoggedMethodCall('pickVideo', arguments: { + }, + ), + const _LoggedMethodCall( + 'pickVideo', + arguments: { 'source': SourceType.camera, 'maxDuration': 10, 'cameraDevice': SourceCamera.rear, - }), - const _LoggedMethodCall('pickVideo', arguments: { + }, + ), + const _LoggedMethodCall( + 'pickVideo', + arguments: { 'source': SourceType.camera, 'maxDuration': 60, 'cameraDevice': SourceCamera.rear, - }), - const _LoggedMethodCall('pickVideo', arguments: { + }, + ), + const _LoggedMethodCall( + 'pickVideo', + arguments: { 'source': SourceType.camera, 'maxDuration': 3600, 'cameraDevice': SourceCamera.rear, - }), - ], - ); + }, + ), + ]); }); test('handles a null video path response gracefully', () async { @@ -1271,16 +1358,16 @@ void main() { test('camera position defaults to back', () async { await picker.getVideo(source: ImageSource.camera); - expect( - log.calls, - <_LoggedMethodCall>[ - const _LoggedMethodCall('pickVideo', arguments: { + expect(log.calls, <_LoggedMethodCall>[ + const _LoggedMethodCall( + 'pickVideo', + arguments: { 'source': SourceType.camera, 'cameraDevice': SourceCamera.rear, 'maxDuration': null, - }), - ], - ); + }, + ), + ]); }); test('camera position can set to front', () async { @@ -1289,16 +1376,16 @@ void main() { preferredCameraDevice: CameraDevice.front, ); - expect( - log.calls, - <_LoggedMethodCall>[ - const _LoggedMethodCall('pickVideo', arguments: { + expect(log.calls, <_LoggedMethodCall>[ + const _LoggedMethodCall( + 'pickVideo', + arguments: { 'source': SourceType.camera, 'maxDuration': null, 'cameraDevice': SourceCamera.front, - }), - ], - ); + }, + ), + ]); }); }); @@ -1307,36 +1394,29 @@ void main() { log.returnValue = ['/foo.mp4', 'bar.mp4']; await picker.getMultiVideoWithOptions(); - expect( - log.calls, - <_LoggedMethodCall>[ - const _LoggedMethodCall('pickMultiVideo', - arguments: { - 'maxDuration': null, - 'limit': null, - }), - ], - ); + expect(log.calls, <_LoggedMethodCall>[ + const _LoggedMethodCall( + 'pickMultiVideo', + arguments: {'maxDuration': null, 'limit': null}, + ), + ]); }); test('passes the arguments correctly', () async { log.returnValue = []; await picker.getMultiVideoWithOptions( - options: const MultiVideoPickerOptions( - maxDuration: Duration(seconds: 10), - limit: 5, - )); - - expect( - log.calls, - <_LoggedMethodCall>[ - const _LoggedMethodCall('pickMultiVideo', - arguments: { - 'maxDuration': 10, - 'limit': 5, - }), - ], + options: const MultiVideoPickerOptions( + maxDuration: Duration(seconds: 10), + limit: 5, + ), ); + + expect(log.calls, <_LoggedMethodCall>[ + const _LoggedMethodCall( + 'pickMultiVideo', + arguments: {'maxDuration': 10, 'limit': 5}, + ), + ]); }); }); @@ -1345,27 +1425,30 @@ void main() { await picker.getImageFromSource(source: ImageSource.camera); await picker.getImageFromSource(source: ImageSource.gallery); - expect( - log.calls, - <_LoggedMethodCall>[ - const _LoggedMethodCall('pickImage', arguments: { + 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: { + }, + ), + const _LoggedMethodCall( + 'pickImage', + arguments: { 'source': SourceType.gallery, 'maxWidth': null, 'maxHeight': null, 'imageQuality': null, 'cameraDevice': SourceCamera.rear, 'requestFullMetadata': true, - }), - ], - ); + }, + ), + ]); }); test('passes the width and height arguments correctly', () async { @@ -1380,24 +1463,15 @@ void main() { ); await picker.getImageFromSource( source: ImageSource.camera, - options: const ImagePickerOptions( - maxWidth: 10.0, - maxHeight: 20.0, - ), + options: const ImagePickerOptions(maxWidth: 10.0, maxHeight: 20.0), ); await picker.getImageFromSource( source: ImageSource.camera, - options: const ImagePickerOptions( - maxWidth: 10.0, - imageQuality: 70, - ), + options: const ImagePickerOptions(maxWidth: 10.0, imageQuality: 70), ); await picker.getImageFromSource( source: ImageSource.camera, - options: const ImagePickerOptions( - maxHeight: 10.0, - imageQuality: 70, - ), + options: const ImagePickerOptions(maxHeight: 10.0, imageQuality: 70), ); await picker.getImageFromSource( source: ImageSource.camera, @@ -1408,67 +1482,85 @@ void main() { ), ); - expect( - log.calls, - <_LoggedMethodCall>[ - const _LoggedMethodCall('pickImage', arguments: { + 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: { + }, + ), + const _LoggedMethodCall( + 'pickImage', + arguments: { 'source': SourceType.camera, 'maxWidth': 10.0, 'maxHeight': null, 'imageQuality': null, 'cameraDevice': SourceCamera.rear, 'requestFullMetadata': true, - }), - const _LoggedMethodCall('pickImage', arguments: { + }, + ), + const _LoggedMethodCall( + 'pickImage', + arguments: { 'source': SourceType.camera, 'maxWidth': null, 'maxHeight': 10.0, 'imageQuality': null, 'cameraDevice': SourceCamera.rear, 'requestFullMetadata': true, - }), - const _LoggedMethodCall('pickImage', arguments: { + }, + ), + const _LoggedMethodCall( + 'pickImage', + arguments: { 'source': SourceType.camera, 'maxWidth': 10.0, 'maxHeight': 20.0, 'imageQuality': null, 'cameraDevice': SourceCamera.rear, 'requestFullMetadata': true, - }), - const _LoggedMethodCall('pickImage', arguments: { + }, + ), + const _LoggedMethodCall( + 'pickImage', + arguments: { 'source': SourceType.camera, 'maxWidth': 10.0, 'maxHeight': null, 'imageQuality': 70, 'cameraDevice': SourceCamera.rear, 'requestFullMetadata': true, - }), - const _LoggedMethodCall('pickImage', arguments: { + }, + ), + const _LoggedMethodCall( + 'pickImage', + arguments: { 'source': SourceType.camera, 'maxWidth': null, 'maxHeight': 10.0, 'imageQuality': 70, 'cameraDevice': SourceCamera.rear, 'requestFullMetadata': true, - }), - const _LoggedMethodCall('pickImage', arguments: { + }, + ), + const _LoggedMethodCall( + 'pickImage', + arguments: { 'source': SourceType.camera, 'maxWidth': 10.0, 'maxHeight': 20.0, 'imageQuality': 70, 'cameraDevice': SourceCamera.rear, 'requestFullMetadata': true, - }), - ], - ); + }, + ), + ]); }); test('does not accept a invalid imageQuality argument', () { @@ -1527,67 +1619,72 @@ void main() { log.returnValue = null; expect( - await picker.getImageFromSource(source: ImageSource.gallery), isNull); + await picker.getImageFromSource(source: ImageSource.gallery), + isNull, + ); expect( - await picker.getImageFromSource(source: ImageSource.camera), isNull); + await picker.getImageFromSource(source: ImageSource.camera), + isNull, + ); }); test('camera position defaults to back', () async { await picker.getImageFromSource(source: ImageSource.camera); - expect( - log.calls, - <_LoggedMethodCall>[ - const _LoggedMethodCall('pickImage', arguments: { + 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 { await picker.getImageFromSource( source: ImageSource.camera, - options: - const ImagePickerOptions(preferredCameraDevice: CameraDevice.front), + options: const ImagePickerOptions( + preferredCameraDevice: CameraDevice.front, + ), ); - expect( - log.calls, - <_LoggedMethodCall>[ - const _LoggedMethodCall('pickImage', arguments: { + 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: { + expect(log.calls, <_LoggedMethodCall>[ + const _LoggedMethodCall( + 'pickImage', + arguments: { 'source': SourceType.gallery, 'maxWidth': null, 'maxHeight': null, 'imageQuality': null, 'cameraDevice': SourceCamera.rear, 'requestFullMetadata': true, - }), - ], - ); + }, + ), + ]); }); test('passes the request full metadata argument correctly', () async { @@ -1596,19 +1693,19 @@ void main() { options: const ImagePickerOptions(requestFullMetadata: false), ); - expect( - log.calls, - <_LoggedMethodCall>[ - const _LoggedMethodCall('pickImage', arguments: { + expect(log.calls, <_LoggedMethodCall>[ + const _LoggedMethodCall( + 'pickImage', + arguments: { 'source': SourceType.gallery, 'maxWidth': null, 'maxHeight': null, 'imageQuality': null, 'cameraDevice': SourceCamera.rear, 'requestFullMetadata': false, - }), - ], - ); + }, + ), + ]); }); }); @@ -1617,19 +1714,18 @@ void main() { 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, - }), - ], - ); + expect(log.calls, <_LoggedMethodCall>[ + const _LoggedMethodCall( + 'pickMultiImage', + arguments: { + 'maxWidth': null, + 'maxHeight': null, + 'imageQuality': null, + 'requestFullMetadata': true, + 'limit': null, + }, + ), + ]); }); test('passes the width and height arguments correctly', () async { @@ -1680,75 +1776,88 @@ void main() { ), ); - 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(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, + }, + ), + ]); }); test('does not accept a negative width or height argument', () { @@ -1797,18 +1906,14 @@ void main() { log.returnValue = ['0', '1']; expect( () => picker.getMultiImageWithOptions( - options: const MultiImagePickerOptions( - limit: -1, - ), + options: const MultiImagePickerOptions(limit: -1), ), throwsArgumentError, ); expect( () => picker.getMultiImageWithOptions( - options: const MultiImagePickerOptions( - limit: 0, - ), + options: const MultiImagePickerOptions(limit: 0), ), throwsArgumentError, ); @@ -1824,19 +1929,18 @@ void main() { 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, - }), - ], - ); + 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 { @@ -1847,19 +1951,18 @@ void main() { ), ); - expect( - log.calls, - <_LoggedMethodCall>[ - const _LoggedMethodCall('pickMultiImage', - arguments: { - 'maxWidth': null, - 'maxHeight': null, - 'imageQuality': null, - 'requestFullMetadata': false, - 'limit': null, - }), - ], - ); + expect(log.calls, <_LoggedMethodCall>[ + const _LoggedMethodCall( + 'pickMultiImage', + arguments: { + 'maxWidth': null, + 'maxHeight': null, + 'imageQuality': null, + 'requestFullMetadata': false, + 'limit': null, + }, + ), + ]); }); }); } 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 index caa53c799e2..9c7683433f2 100644 --- a/packages/image_picker/image_picker_ios/test/test_api.g.dart +++ b/packages/image_picker/image_picker_ios/test/test_api.g.dart @@ -66,14 +66,24 @@ abstract class TestHostImagePickerApi { TestDefaultBinaryMessengerBinding.instance; static const MessageCodec pigeonChannelCodec = _PigeonCodec(); - Future pickImage(SourceSpecification source, MaxSize maxSize, - int? imageQuality, bool requestFullMetadata); + Future pickImage( + SourceSpecification source, + MaxSize maxSize, + int? imageQuality, + bool requestFullMetadata, + ); Future> pickMultiImage( - MaxSize maxSize, int? imageQuality, bool requestFullMetadata, int? limit); + MaxSize maxSize, + int? imageQuality, + bool requestFullMetadata, + int? limit, + ); Future pickVideo( - SourceSpecification source, int? maxDurationSeconds); + SourceSpecification source, + int? maxDurationSeconds, + ); Future> pickMultiVideo(int? maxDurationSeconds, int? limit); @@ -88,183 +98,237 @@ abstract class TestHostImagePickerApi { messageChannelSuffix = messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; { - final BasicMessageChannel< - Object?> pigeonVar_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.image_picker_ios.ImagePickerApi.pickImage$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); + 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(pigeonVar_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.image_picker_ios.ImagePickerApi.pickImage was null.'); + _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.'); + 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.'); + 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.'); + 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!); + 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())); + error: PlatformException(code: 'error', message: e.toString()), + ); } }); } } { - final BasicMessageChannel< - Object?> pigeonVar_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.image_picker_ios.ImagePickerApi.pickMultiImage$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); + 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(pigeonVar_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.image_picker_ios.ImagePickerApi.pickMultiImage was null.'); + _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.'); + 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.'); + 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); + 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())); + error: PlatformException(code: 'error', message: e.toString()), + ); } }); } } { - final BasicMessageChannel< - Object?> pigeonVar_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.image_picker_ios.ImagePickerApi.pickVideo$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); + 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())); - } - }); + .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< - Object?> pigeonVar_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.image_picker_ios.ImagePickerApi.pickMultiVideo$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); + 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())); - } - }); + .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< - Object?> pigeonVar_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.image_picker_ios.ImagePickerApi.pickMedia$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); + 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())); - } - }); + .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(), + ), + ); + } + }); } } } diff --git a/packages/image_picker/image_picker_linux/CHANGELOG.md b/packages/image_picker/image_picker_linux/CHANGELOG.md index 95207a3befa..d02a6af7d60 100644 --- a/packages/image_picker/image_picker_linux/CHANGELOG.md +++ b/packages/image_picker/image_picker_linux/CHANGELOG.md @@ -1,3 +1,7 @@ +## NEXT + +* Updates minimum supported SDK version to Flutter 3.29/Dart 3.7. + ## 0.2.2 * Adds support for `getMultiVideoWithOptions`. diff --git a/packages/image_picker/image_picker_linux/example/lib/main.dart b/packages/image_picker/image_picker_linux/example/lib/main.dart index b62d3913397..ff9ebda808c 100644 --- a/packages/image_picker/image_picker_linux/example/lib/main.dart +++ b/packages/image_picker/image_picker_linux/example/lib/main.dart @@ -60,8 +60,9 @@ class _MyHomePageState extends State { Future _playVideo(XFile? file) async { if (file != null && mounted) { await _disposeVideoController(); - final VideoPlayerController controller = - VideoPlayerController.file(File(file.path)); + final VideoPlayerController controller = VideoPlayerController.file( + File(file.path), + ); _controller = controller; await controller.setVolume(1.0); await controller.initialize(); @@ -87,7 +88,9 @@ class _MyHomePageState extends State { files = await _picker.getMultiVideoWithOptions(); } else { final XFile? file = await _picker.getVideo( - source: source, maxDuration: const Duration(seconds: 10)); + source: source, + maxDuration: const Duration(seconds: 10), + ); files = [if (file != null) file]; } if (files.isNotEmpty && context.mounted) { @@ -96,26 +99,30 @@ class _MyHomePageState extends State { await _playVideo(files.first); } } else if (allowMultiple) { - await _displayPickImageDialog(context, - (double? maxWidth, double? maxHeight, int? quality) async { + await _displayPickImageDialog(context, ( + double? maxWidth, + double? maxHeight, + int? quality, + ) async { try { final ImageOptions imageOptions = ImageOptions( maxWidth: maxWidth, maxHeight: maxHeight, imageQuality: quality, ); - final List pickedFileList = isMedia - ? await _picker.getMedia( - options: MediaOptions( - allowMultiple: allowMultiple, - imageOptions: imageOptions, - ), - ) - : await _picker.getMultiImageWithOptions( - options: MultiImagePickerOptions( - imageOptions: imageOptions, - ), - ); + final List pickedFileList = + isMedia + ? await _picker.getMedia( + options: MediaOptions( + allowMultiple: allowMultiple, + imageOptions: imageOptions, + ), + ) + : await _picker.getMultiImageWithOptions( + options: MultiImagePickerOptions( + imageOptions: imageOptions, + ), + ); if (pickedFileList.isNotEmpty && context.mounted) { _showPickedSnackBar(context, pickedFileList); } @@ -129,19 +136,25 @@ class _MyHomePageState extends State { } }); } else if (isMedia) { - await _displayPickImageDialog(context, - (double? maxWidth, double? maxHeight, int? quality) async { + await _displayPickImageDialog(context, ( + double? maxWidth, + double? maxHeight, + int? quality, + ) async { try { final List pickedFileList = []; - final XFile? media = _firstOrNull(await _picker.getMedia( - options: MediaOptions( + final XFile? media = _firstOrNull( + await _picker.getMedia( + options: MediaOptions( allowMultiple: allowMultiple, imageOptions: ImageOptions( maxWidth: maxWidth, maxHeight: maxHeight, imageQuality: quality, - )), - )); + ), + ), + ), + ); if (media != null) { pickedFileList.add(media); @@ -154,8 +167,11 @@ class _MyHomePageState extends State { } }); } else { - await _displayPickImageDialog(context, - (double? maxWidth, double? maxHeight, int? quality) async { + await _displayPickImageDialog(context, ( + double? maxWidth, + double? maxHeight, + int? quality, + ) async { try { final XFile? pickedFile = await _picker.getImageFromSource( source: source, @@ -236,21 +252,27 @@ class _MyHomePageState extends State { return Column( mainAxisSize: MainAxisSize.min, children: [ - Text(image.name, - key: const Key('image_picker_example_picked_image_name')), + Text( + image.name, + key: const Key('image_picker_example_picked_image_name'), + ), Semantics( label: 'image_picker_example_picked_image', - child: mime == null || mime.startsWith('image/') - ? Image.file( - File(_mediaFileList![index].path), - errorBuilder: (BuildContext context, Object error, - StackTrace? stackTrace) { - return const Center( - child: - Text('This image type is not supported')); - }, - ) - : _buildInlineVideoPlayer(index), + child: + mime == null || mime.startsWith('image/') + ? Image.file( + File(_mediaFileList![index].path), + errorBuilder: ( + BuildContext context, + Object error, + StackTrace? stackTrace, + ) { + return const Center( + child: Text('This image type is not supported'), + ); + }, + ) + : _buildInlineVideoPlayer(index), ), ], ); @@ -272,8 +294,9 @@ class _MyHomePageState extends State { } Widget _buildInlineVideoPlayer(int index) { - final VideoPlayerController controller = - VideoPlayerController.file(File(_mediaFileList![index].path)); + final VideoPlayerController controller = VideoPlayerController.file( + File(_mediaFileList![index].path), + ); controller.setVolume(1.0); controller.initialize(); controller.setLooping(true); @@ -292,13 +315,8 @@ class _MyHomePageState extends State { @override Widget build(BuildContext context) { return Scaffold( - appBar: AppBar( - title: Text(widget.title!), - ), - body: Align( - alignment: Alignment.topCenter, - child: _handlePreview(), - ), + appBar: AppBar(title: Text(widget.title!)), + body: Align(alignment: Alignment.topCenter, child: _handlePreview()), floatingActionButton: Column( mainAxisAlignment: MainAxisAlignment.end, children: [ @@ -402,8 +420,11 @@ class _MyHomePageState extends State { backgroundColor: Colors.red, onPressed: () { _isVideo = true; - _onImageButtonPressed(ImageSource.gallery, - context: context, allowMultiple: true); + _onImageButtonPressed( + ImageSource.gallery, + context: context, + allowMultiple: true, + ); }, heroTag: 'multiVideo', tooltip: 'Pick multiple videos', @@ -441,73 +462,87 @@ class _MyHomePageState extends State { } Future _displayPickImageDialog( - BuildContext context, OnPickImageCallback onPick) async { + BuildContext context, + OnPickImageCallback onPick, + ) async { return showDialog( - context: context, - builder: (BuildContext context) { - return AlertDialog( - title: const Text('Add optional parameters'), - content: Column( - children: [ - TextField( - controller: maxWidthController, - keyboardType: - const TextInputType.numberWithOptions(decimal: true), - decoration: const InputDecoration( - hintText: 'Enter maxWidth if desired'), + context: context, + builder: (BuildContext context) { + return AlertDialog( + title: const Text('Add optional parameters'), + content: Column( + children: [ + TextField( + controller: maxWidthController, + keyboardType: const TextInputType.numberWithOptions( + decimal: true, ), - TextField( - controller: maxHeightController, - keyboardType: - const TextInputType.numberWithOptions(decimal: true), - decoration: const InputDecoration( - hintText: 'Enter maxHeight if desired'), + decoration: const InputDecoration( + hintText: 'Enter maxWidth if desired', ), - TextField( - controller: qualityController, - keyboardType: TextInputType.number, - decoration: const InputDecoration( - hintText: 'Enter quality if desired'), + ), + TextField( + controller: maxHeightController, + keyboardType: const TextInputType.numberWithOptions( + decimal: true, + ), + decoration: const InputDecoration( + hintText: 'Enter maxHeight if desired', ), - ], - ), - actions: [ - TextButton( - child: const Text('CANCEL'), - onPressed: () { - Navigator.of(context).pop(); - }, ), - TextButton( - child: const Text('PICK'), - onPressed: () { - final double? width = maxWidthController.text.isNotEmpty + TextField( + controller: qualityController, + keyboardType: TextInputType.number, + decoration: const InputDecoration( + hintText: 'Enter quality if desired', + ), + ), + ], + ), + actions: [ + TextButton( + child: const Text('CANCEL'), + onPressed: () { + Navigator.of(context).pop(); + }, + ), + TextButton( + child: const Text('PICK'), + onPressed: () { + final double? width = + maxWidthController.text.isNotEmpty ? double.parse(maxWidthController.text) : null; - final double? height = maxHeightController.text.isNotEmpty + final double? height = + maxHeightController.text.isNotEmpty ? double.parse(maxHeightController.text) : null; - final int? quality = qualityController.text.isNotEmpty + final int? quality = + qualityController.text.isNotEmpty ? int.parse(qualityController.text) : null; - onPick(width, height, quality); - Navigator.of(context).pop(); - }), - ], - ); - }); + onPick(width, height, quality); + Navigator.of(context).pop(); + }, + ), + ], + ); + }, + ); } void _showPickedSnackBar(BuildContext context, List files) { - ScaffoldMessenger.of(context).showSnackBar(SnackBar( - content: Text('Picked: ${files.map((XFile it) => it.name).join(',')}'), - duration: const Duration(seconds: 2), - )); + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text('Picked: ${files.map((XFile it) => it.name).join(',')}'), + duration: const Duration(seconds: 2), + ), + ); } } -typedef OnPickImageCallback = void Function( - double? maxWidth, double? maxHeight, int? quality); +typedef OnPickImageCallback = + void Function(double? maxWidth, double? maxHeight, int? quality); class AspectRatioVideo extends StatefulWidget { const AspectRatioVideo(this.controller, {super.key}); diff --git a/packages/image_picker/image_picker_linux/example/pubspec.yaml b/packages/image_picker/image_picker_linux/example/pubspec.yaml index b1626f31057..2d9e179c859 100644 --- a/packages/image_picker/image_picker_linux/example/pubspec.yaml +++ b/packages/image_picker/image_picker_linux/example/pubspec.yaml @@ -4,8 +4,8 @@ publish_to: 'none' version: 1.0.0 environment: - sdk: ^3.6.0 - flutter: ">=3.27.0" + sdk: ^3.7.0 + flutter: ">=3.29.0" dependencies: flutter: diff --git a/packages/image_picker/image_picker_linux/lib/image_picker_linux.dart b/packages/image_picker/image_picker_linux/lib/image_picker_linux.dart index deacebaf4e7..83164230dcc 100644 --- a/packages/image_picker/image_picker_linux/lib/image_picker_linux.dart +++ b/packages/image_picker/image_picker_linux/lib/image_picker_linux.dart @@ -35,12 +35,14 @@ class ImagePickerLinux extends CameraDelegatingImagePickerPlatform { CameraDevice preferredCameraDevice = CameraDevice.rear, }) async { final XFile? file = await getImageFromSource( - source: source, - options: ImagePickerOptions( - maxWidth: maxWidth, - maxHeight: maxHeight, - imageQuality: imageQuality, - preferredCameraDevice: preferredCameraDevice)); + source: source, + options: ImagePickerOptions( + maxWidth: maxWidth, + maxHeight: maxHeight, + imageQuality: imageQuality, + preferredCameraDevice: preferredCameraDevice, + ), + ); if (file != null) { return PickedFile(file.path); } @@ -56,9 +58,10 @@ class ImagePickerLinux extends CameraDelegatingImagePickerPlatform { Duration? maxDuration, }) async { final XFile? file = await getVideo( - source: source, - preferredCameraDevice: preferredCameraDevice, - maxDuration: maxDuration); + source: source, + preferredCameraDevice: preferredCameraDevice, + maxDuration: maxDuration, + ); if (file != null) { return PickedFile(file.path); } @@ -76,12 +79,14 @@ class ImagePickerLinux extends CameraDelegatingImagePickerPlatform { CameraDevice preferredCameraDevice = CameraDevice.rear, }) async { return getImageFromSource( - source: source, - options: ImagePickerOptions( - maxWidth: maxWidth, - maxHeight: maxHeight, - imageQuality: imageQuality, - preferredCameraDevice: preferredCameraDevice)); + source: source, + options: ImagePickerOptions( + maxWidth: maxWidth, + maxHeight: maxHeight, + imageQuality: imageQuality, + preferredCameraDevice: preferredCameraDevice, + ), + ); } // [ImagePickerOptions] options are not currently supported. If any @@ -98,10 +103,13 @@ class ImagePickerLinux extends CameraDelegatingImagePickerPlatform { case ImageSource.camera: return super.getImageFromSource(source: source); case ImageSource.gallery: - const XTypeGroup typeGroup = - XTypeGroup(label: 'Images', mimeTypes: ['image/*']); - final XFile? file = await fileSelector - .openFile(acceptedTypeGroups: [typeGroup]); + const XTypeGroup typeGroup = XTypeGroup( + label: 'Images', + mimeTypes: ['image/*'], + ); + final XFile? file = await fileSelector.openFile( + acceptedTypeGroups: [typeGroup], + ); return file; } // Ensure that there's a fallback in case a new source is added. @@ -124,14 +132,18 @@ class ImagePickerLinux extends CameraDelegatingImagePickerPlatform { switch (source) { case ImageSource.camera: return super.getVideo( - source: source, - preferredCameraDevice: preferredCameraDevice, - maxDuration: maxDuration); + source: source, + preferredCameraDevice: preferredCameraDevice, + maxDuration: maxDuration, + ); case ImageSource.gallery: - const XTypeGroup typeGroup = - XTypeGroup(label: 'Videos', mimeTypes: ['video/*']); - final XFile? file = await fileSelector - .openFile(acceptedTypeGroups: [typeGroup]); + const XTypeGroup typeGroup = XTypeGroup( + label: 'Videos', + mimeTypes: ['video/*'], + ); + final XFile? file = await fileSelector.openFile( + acceptedTypeGroups: [typeGroup], + ); return file; } // Ensure that there's a fallback in case a new source is added. @@ -148,21 +160,27 @@ class ImagePickerLinux extends CameraDelegatingImagePickerPlatform { double? maxHeight, int? imageQuality, }) async { - const XTypeGroup typeGroup = - XTypeGroup(label: 'Images', mimeTypes: ['image/*']); - final List files = await fileSelector - .openFiles(acceptedTypeGroups: [typeGroup]); + const XTypeGroup typeGroup = XTypeGroup( + label: 'Images', + mimeTypes: ['image/*'], + ); + final List files = await fileSelector.openFiles( + acceptedTypeGroups: [typeGroup], + ); return files; } @override - Future> getMultiVideoWithOptions( - {MultiVideoPickerOptions options = - const MultiVideoPickerOptions()}) async { - const XTypeGroup typeGroup = - XTypeGroup(label: 'Videos', mimeTypes: ['video/*']); - final List files = await fileSelector - .openFiles(acceptedTypeGroups: [typeGroup]); + Future> getMultiVideoWithOptions({ + MultiVideoPickerOptions options = const MultiVideoPickerOptions(), + }) async { + const XTypeGroup typeGroup = XTypeGroup( + label: 'Videos', + mimeTypes: ['video/*'], + ); + final List files = await fileSelector.openFiles( + acceptedTypeGroups: [typeGroup], + ); return files; } @@ -179,14 +197,14 @@ class ImagePickerLinux extends CameraDelegatingImagePickerPlatform { List files; if (options.allowMultiple) { - files = await fileSelector - .openFiles(acceptedTypeGroups: [typeGroup]); + files = await fileSelector.openFiles( + acceptedTypeGroups: [typeGroup], + ); } else { - final XFile? file = await fileSelector - .openFile(acceptedTypeGroups: [typeGroup]); - files = [ - if (file != null) file, - ]; + final XFile? file = await fileSelector.openFile( + acceptedTypeGroups: [typeGroup], + ); + files = [if (file != null) file]; } return files; } diff --git a/packages/image_picker/image_picker_linux/pubspec.yaml b/packages/image_picker/image_picker_linux/pubspec.yaml index ba1d4c4d71f..b1d74b9b723 100644 --- a/packages/image_picker/image_picker_linux/pubspec.yaml +++ b/packages/image_picker/image_picker_linux/pubspec.yaml @@ -5,8 +5,8 @@ issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+ version: 0.2.2 environment: - sdk: ^3.6.0 - flutter: ">=3.27.0" + sdk: ^3.7.0 + flutter: ">=3.29.0" flutter: plugin: diff --git a/packages/image_picker/image_picker_linux/test/image_picker_linux_test.dart b/packages/image_picker/image_picker_linux/test/image_picker_linux_test.dart index c9fd87868c6..11172576351 100644 --- a/packages/image_picker/image_picker_linux/test/image_picker_linux_test.dart +++ b/packages/image_picker/image_picker_linux/test/image_picker_linux_test.dart @@ -28,13 +28,17 @@ void main() { plugin = ImagePickerLinux(); mockFileSelectorPlatform = MockFileSelectorPlatform(); - when(mockFileSelectorPlatform.openFile( - acceptedTypeGroups: anyNamed('acceptedTypeGroups'))) - .thenAnswer((_) async => null); - - when(mockFileSelectorPlatform.openFiles( - acceptedTypeGroups: anyNamed('acceptedTypeGroups'))) - .thenAnswer((_) async => List.empty()); + when( + mockFileSelectorPlatform.openFile( + acceptedTypeGroups: anyNamed('acceptedTypeGroups'), + ), + ).thenAnswer((_) async => null); + + when( + mockFileSelectorPlatform.openFiles( + acceptedTypeGroups: anyNamed('acceptedTypeGroups'), + ), + ).thenAnswer((_) async => List.empty()); ImagePickerLinux.fileSelector = mockFileSelectorPlatform; }); @@ -48,49 +52,66 @@ void main() { test('pickImage passes the accepted type groups correctly', () async { await plugin.pickImage(source: ImageSource.gallery); - final VerificationResult result = verify(mockFileSelectorPlatform - .openFile(acceptedTypeGroups: captureAnyNamed('acceptedTypeGroups'))); + final VerificationResult result = verify( + mockFileSelectorPlatform.openFile( + acceptedTypeGroups: captureAnyNamed('acceptedTypeGroups'), + ), + ); expect(capturedTypeGroups(result)[0].mimeTypes, ['image/*']); }); test('getImage passes the accepted type groups correctly', () async { await plugin.getImage(source: ImageSource.gallery); - final VerificationResult result = verify(mockFileSelectorPlatform - .openFile(acceptedTypeGroups: captureAnyNamed('acceptedTypeGroups'))); + final VerificationResult result = verify( + mockFileSelectorPlatform.openFile( + acceptedTypeGroups: captureAnyNamed('acceptedTypeGroups'), + ), + ); expect(capturedTypeGroups(result)[0].mimeTypes, ['image/*']); }); - test('getImageFromSource passes the accepted type groups correctly', - () async { - await plugin.getImageFromSource(source: ImageSource.gallery); + test( + 'getImageFromSource passes the accepted type groups correctly', + () async { + await plugin.getImageFromSource(source: ImageSource.gallery); - final VerificationResult result = verify(mockFileSelectorPlatform - .openFile(acceptedTypeGroups: captureAnyNamed('acceptedTypeGroups'))); - expect(capturedTypeGroups(result)[0].mimeTypes, ['image/*']); - }); + final VerificationResult result = verify( + mockFileSelectorPlatform.openFile( + acceptedTypeGroups: captureAnyNamed('acceptedTypeGroups'), + ), + ); + expect(capturedTypeGroups(result)[0].mimeTypes, ['image/*']); + }, + ); test('getImageFromSource calls delegate when source is camera', () async { const String fakePath = '/tmp/foo'; plugin.cameraDelegate = FakeCameraDelegate(result: XFile(fakePath)); expect( - (await plugin.getImageFromSource(source: ImageSource.camera))!.path, - fakePath); + (await plugin.getImageFromSource(source: ImageSource.camera))!.path, + fakePath, + ); }); test( - 'getImageFromSource throws StateError when source is camera with no delegate', - () async { - await expectLater(plugin.getImageFromSource(source: ImageSource.camera), - throwsStateError); - }); + 'getImageFromSource throws StateError when source is camera with no delegate', + () async { + await expectLater( + plugin.getImageFromSource(source: ImageSource.camera), + throwsStateError, + ); + }, + ); test('getMultiImage passes the accepted type groups correctly', () async { await plugin.getMultiImage(); final VerificationResult result = verify( - mockFileSelectorPlatform.openFiles( - acceptedTypeGroups: captureAnyNamed('acceptedTypeGroups'))); + mockFileSelectorPlatform.openFiles( + acceptedTypeGroups: captureAnyNamed('acceptedTypeGroups'), + ), + ); expect(capturedTypeGroups(result)[0].mimeTypes, ['image/*']); }); }); @@ -99,16 +120,22 @@ void main() { test('pickVideo passes the accepted type groups correctly', () async { await plugin.pickVideo(source: ImageSource.gallery); - final VerificationResult result = verify(mockFileSelectorPlatform - .openFile(acceptedTypeGroups: captureAnyNamed('acceptedTypeGroups'))); + final VerificationResult result = verify( + mockFileSelectorPlatform.openFile( + acceptedTypeGroups: captureAnyNamed('acceptedTypeGroups'), + ), + ); expect(capturedTypeGroups(result)[0].mimeTypes, ['video/*']); }); test('getVideo passes the accepted type groups correctly', () async { await plugin.getVideo(source: ImageSource.gallery); - final VerificationResult result = verify(mockFileSelectorPlatform - .openFile(acceptedTypeGroups: captureAnyNamed('acceptedTypeGroups'))); + final VerificationResult result = verify( + mockFileSelectorPlatform.openFile( + acceptedTypeGroups: captureAnyNamed('acceptedTypeGroups'), + ), + ); expect(capturedTypeGroups(result)[0].mimeTypes, ['video/*']); }); @@ -116,24 +143,34 @@ void main() { const String fakePath = '/tmp/foo'; plugin.cameraDelegate = FakeCameraDelegate(result: XFile(fakePath)); expect( - (await plugin.getVideo(source: ImageSource.camera))!.path, fakePath); + (await plugin.getVideo(source: ImageSource.camera))!.path, + fakePath, + ); }); - test('getVideo throws StateError when source is camera with no delegate', - () async { - await expectLater( - plugin.getVideo(source: ImageSource.camera), throwsStateError); - }); + test( + 'getVideo throws StateError when source is camera with no delegate', + () async { + await expectLater( + plugin.getVideo(source: ImageSource.camera), + throwsStateError, + ); + }, + ); - test('getMultiVideoWithOptions passes the accepted type groups correctly', - () async { - await plugin.getMultiVideoWithOptions(); + test( + 'getMultiVideoWithOptions passes the accepted type groups correctly', + () async { + await plugin.getMultiVideoWithOptions(); - final VerificationResult result = verify( + final VerificationResult result = verify( mockFileSelectorPlatform.openFiles( - acceptedTypeGroups: captureAnyNamed('acceptedTypeGroups'))); - expect(capturedTypeGroups(result)[0].mimeTypes, ['video/*']); - }); + acceptedTypeGroups: captureAnyNamed('acceptedTypeGroups'), + ), + ); + expect(capturedTypeGroups(result)[0].mimeTypes, ['video/*']); + }, + ); }); group('media', () { @@ -141,30 +178,30 @@ void main() { await plugin.getMedia(options: const MediaOptions(allowMultiple: true)); final VerificationResult result = verify( - mockFileSelectorPlatform.openFiles( - acceptedTypeGroups: captureAnyNamed('acceptedTypeGroups'))); - expect(capturedTypeGroups(result)[0].mimeTypes, - ['image/*', 'video/*']); + mockFileSelectorPlatform.openFiles( + acceptedTypeGroups: captureAnyNamed('acceptedTypeGroups'), + ), + ); + expect(capturedTypeGroups(result)[0].mimeTypes, [ + 'image/*', + 'video/*', + ]); }); test('multiple media handles an empty path response gracefully', () async { expect( - await plugin.getMedia( - options: const MediaOptions( - allowMultiple: true, - ), - ), - []); + await plugin.getMedia(options: const MediaOptions(allowMultiple: true)), + [], + ); }); test('single media handles an empty path response gracefully', () async { expect( - await plugin.getMedia( - options: const MediaOptions( - allowMultiple: false, - ), - ), - []); + await plugin.getMedia( + options: const MediaOptions(allowMultiple: false), + ), + [], + ); }); }); } @@ -175,16 +212,18 @@ class FakeCameraDelegate extends ImagePickerCameraDelegate { XFile? result; @override - Future takePhoto( - {ImagePickerCameraDelegateOptions options = - const ImagePickerCameraDelegateOptions()}) async { + Future takePhoto({ + ImagePickerCameraDelegateOptions options = + const ImagePickerCameraDelegateOptions(), + }) async { return result; } @override - Future takeVideo( - {ImagePickerCameraDelegateOptions options = - const ImagePickerCameraDelegateOptions()}) async { + Future takeVideo({ + ImagePickerCameraDelegateOptions options = + const ImagePickerCameraDelegateOptions(), + }) async { return result; } } diff --git a/packages/image_picker/image_picker_linux/test/image_picker_linux_test.mocks.dart b/packages/image_picker/image_picker_linux/test/image_picker_linux_test.mocks.dart index 5980f991687..3f78fa4574a 100644 --- a/packages/image_picker/image_picker_linux/test/image_picker_linux_test.mocks.dart +++ b/packages/image_picker/image_picker_linux/test/image_picker_linux_test.mocks.dart @@ -38,17 +38,14 @@ class MockFileSelectorPlatform extends _i1.Mock String? confirmButtonText, }) => (super.noSuchMethod( - Invocation.method( - #openFile, - [], - { - #acceptedTypeGroups: acceptedTypeGroups, - #initialDirectory: initialDirectory, - #confirmButtonText: confirmButtonText, - }, - ), - returnValue: _i3.Future<_i2.XFile?>.value(), - ) as _i3.Future<_i2.XFile?>); + Invocation.method(#openFile, [], { + #acceptedTypeGroups: acceptedTypeGroups, + #initialDirectory: initialDirectory, + #confirmButtonText: confirmButtonText, + }), + returnValue: _i3.Future<_i2.XFile?>.value(), + ) + as _i3.Future<_i2.XFile?>); @override _i3.Future> openFiles({ @@ -57,17 +54,14 @@ class MockFileSelectorPlatform extends _i1.Mock String? confirmButtonText, }) => (super.noSuchMethod( - Invocation.method( - #openFiles, - [], - { - #acceptedTypeGroups: acceptedTypeGroups, - #initialDirectory: initialDirectory, - #confirmButtonText: confirmButtonText, - }, - ), - returnValue: _i3.Future>.value(<_i2.XFile>[]), - ) as _i3.Future>); + Invocation.method(#openFiles, [], { + #acceptedTypeGroups: acceptedTypeGroups, + #initialDirectory: initialDirectory, + #confirmButtonText: confirmButtonText, + }), + returnValue: _i3.Future>.value(<_i2.XFile>[]), + ) + as _i3.Future>); @override _i3.Future getSavePath({ @@ -77,18 +71,15 @@ class MockFileSelectorPlatform extends _i1.Mock String? confirmButtonText, }) => (super.noSuchMethod( - Invocation.method( - #getSavePath, - [], - { - #acceptedTypeGroups: acceptedTypeGroups, - #initialDirectory: initialDirectory, - #suggestedName: suggestedName, - #confirmButtonText: confirmButtonText, - }, - ), - returnValue: _i3.Future.value(), - ) as _i3.Future); + Invocation.method(#getSavePath, [], { + #acceptedTypeGroups: acceptedTypeGroups, + #initialDirectory: initialDirectory, + #suggestedName: suggestedName, + #confirmButtonText: confirmButtonText, + }), + returnValue: _i3.Future.value(), + ) + as _i3.Future); @override _i3.Future<_i2.FileSaveLocation?> getSaveLocation({ @@ -96,16 +87,13 @@ class MockFileSelectorPlatform extends _i1.Mock _i2.SaveDialogOptions? options = const _i2.SaveDialogOptions(), }) => (super.noSuchMethod( - Invocation.method( - #getSaveLocation, - [], - { - #acceptedTypeGroups: acceptedTypeGroups, - #options: options, - }, - ), - returnValue: _i3.Future<_i2.FileSaveLocation?>.value(), - ) as _i3.Future<_i2.FileSaveLocation?>); + Invocation.method(#getSaveLocation, [], { + #acceptedTypeGroups: acceptedTypeGroups, + #options: options, + }), + returnValue: _i3.Future<_i2.FileSaveLocation?>.value(), + ) + as _i3.Future<_i2.FileSaveLocation?>); @override _i3.Future getDirectoryPath({ @@ -113,16 +101,13 @@ class MockFileSelectorPlatform extends _i1.Mock String? confirmButtonText, }) => (super.noSuchMethod( - Invocation.method( - #getDirectoryPath, - [], - { - #initialDirectory: initialDirectory, - #confirmButtonText: confirmButtonText, - }, - ), - returnValue: _i3.Future.value(), - ) as _i3.Future); + Invocation.method(#getDirectoryPath, [], { + #initialDirectory: initialDirectory, + #confirmButtonText: confirmButtonText, + }), + returnValue: _i3.Future.value(), + ) + as _i3.Future); @override _i3.Future> getDirectoryPaths({ @@ -130,14 +115,11 @@ class MockFileSelectorPlatform extends _i1.Mock String? confirmButtonText, }) => (super.noSuchMethod( - Invocation.method( - #getDirectoryPaths, - [], - { - #initialDirectory: initialDirectory, - #confirmButtonText: confirmButtonText, - }, - ), - returnValue: _i3.Future>.value([]), - ) as _i3.Future>); + Invocation.method(#getDirectoryPaths, [], { + #initialDirectory: initialDirectory, + #confirmButtonText: confirmButtonText, + }), + returnValue: _i3.Future>.value([]), + ) + as _i3.Future>); } diff --git a/packages/image_picker/image_picker_macos/CHANGELOG.md b/packages/image_picker/image_picker_macos/CHANGELOG.md index ab17993adcb..4471e790073 100644 --- a/packages/image_picker/image_picker_macos/CHANGELOG.md +++ b/packages/image_picker/image_picker_macos/CHANGELOG.md @@ -1,3 +1,7 @@ +## NEXT + +* Updates minimum supported SDK version to Flutter 3.29/Dart 3.7. + ## 0.2.2 * Adds support for `getMultiVideoWithOptions`. diff --git a/packages/image_picker/image_picker_macos/example/lib/main.dart b/packages/image_picker/image_picker_macos/example/lib/main.dart index b62d3913397..ff9ebda808c 100644 --- a/packages/image_picker/image_picker_macos/example/lib/main.dart +++ b/packages/image_picker/image_picker_macos/example/lib/main.dart @@ -60,8 +60,9 @@ class _MyHomePageState extends State { Future _playVideo(XFile? file) async { if (file != null && mounted) { await _disposeVideoController(); - final VideoPlayerController controller = - VideoPlayerController.file(File(file.path)); + final VideoPlayerController controller = VideoPlayerController.file( + File(file.path), + ); _controller = controller; await controller.setVolume(1.0); await controller.initialize(); @@ -87,7 +88,9 @@ class _MyHomePageState extends State { files = await _picker.getMultiVideoWithOptions(); } else { final XFile? file = await _picker.getVideo( - source: source, maxDuration: const Duration(seconds: 10)); + source: source, + maxDuration: const Duration(seconds: 10), + ); files = [if (file != null) file]; } if (files.isNotEmpty && context.mounted) { @@ -96,26 +99,30 @@ class _MyHomePageState extends State { await _playVideo(files.first); } } else if (allowMultiple) { - await _displayPickImageDialog(context, - (double? maxWidth, double? maxHeight, int? quality) async { + await _displayPickImageDialog(context, ( + double? maxWidth, + double? maxHeight, + int? quality, + ) async { try { final ImageOptions imageOptions = ImageOptions( maxWidth: maxWidth, maxHeight: maxHeight, imageQuality: quality, ); - final List pickedFileList = isMedia - ? await _picker.getMedia( - options: MediaOptions( - allowMultiple: allowMultiple, - imageOptions: imageOptions, - ), - ) - : await _picker.getMultiImageWithOptions( - options: MultiImagePickerOptions( - imageOptions: imageOptions, - ), - ); + final List pickedFileList = + isMedia + ? await _picker.getMedia( + options: MediaOptions( + allowMultiple: allowMultiple, + imageOptions: imageOptions, + ), + ) + : await _picker.getMultiImageWithOptions( + options: MultiImagePickerOptions( + imageOptions: imageOptions, + ), + ); if (pickedFileList.isNotEmpty && context.mounted) { _showPickedSnackBar(context, pickedFileList); } @@ -129,19 +136,25 @@ class _MyHomePageState extends State { } }); } else if (isMedia) { - await _displayPickImageDialog(context, - (double? maxWidth, double? maxHeight, int? quality) async { + await _displayPickImageDialog(context, ( + double? maxWidth, + double? maxHeight, + int? quality, + ) async { try { final List pickedFileList = []; - final XFile? media = _firstOrNull(await _picker.getMedia( - options: MediaOptions( + final XFile? media = _firstOrNull( + await _picker.getMedia( + options: MediaOptions( allowMultiple: allowMultiple, imageOptions: ImageOptions( maxWidth: maxWidth, maxHeight: maxHeight, imageQuality: quality, - )), - )); + ), + ), + ), + ); if (media != null) { pickedFileList.add(media); @@ -154,8 +167,11 @@ class _MyHomePageState extends State { } }); } else { - await _displayPickImageDialog(context, - (double? maxWidth, double? maxHeight, int? quality) async { + await _displayPickImageDialog(context, ( + double? maxWidth, + double? maxHeight, + int? quality, + ) async { try { final XFile? pickedFile = await _picker.getImageFromSource( source: source, @@ -236,21 +252,27 @@ class _MyHomePageState extends State { return Column( mainAxisSize: MainAxisSize.min, children: [ - Text(image.name, - key: const Key('image_picker_example_picked_image_name')), + Text( + image.name, + key: const Key('image_picker_example_picked_image_name'), + ), Semantics( label: 'image_picker_example_picked_image', - child: mime == null || mime.startsWith('image/') - ? Image.file( - File(_mediaFileList![index].path), - errorBuilder: (BuildContext context, Object error, - StackTrace? stackTrace) { - return const Center( - child: - Text('This image type is not supported')); - }, - ) - : _buildInlineVideoPlayer(index), + child: + mime == null || mime.startsWith('image/') + ? Image.file( + File(_mediaFileList![index].path), + errorBuilder: ( + BuildContext context, + Object error, + StackTrace? stackTrace, + ) { + return const Center( + child: Text('This image type is not supported'), + ); + }, + ) + : _buildInlineVideoPlayer(index), ), ], ); @@ -272,8 +294,9 @@ class _MyHomePageState extends State { } Widget _buildInlineVideoPlayer(int index) { - final VideoPlayerController controller = - VideoPlayerController.file(File(_mediaFileList![index].path)); + final VideoPlayerController controller = VideoPlayerController.file( + File(_mediaFileList![index].path), + ); controller.setVolume(1.0); controller.initialize(); controller.setLooping(true); @@ -292,13 +315,8 @@ class _MyHomePageState extends State { @override Widget build(BuildContext context) { return Scaffold( - appBar: AppBar( - title: Text(widget.title!), - ), - body: Align( - alignment: Alignment.topCenter, - child: _handlePreview(), - ), + appBar: AppBar(title: Text(widget.title!)), + body: Align(alignment: Alignment.topCenter, child: _handlePreview()), floatingActionButton: Column( mainAxisAlignment: MainAxisAlignment.end, children: [ @@ -402,8 +420,11 @@ class _MyHomePageState extends State { backgroundColor: Colors.red, onPressed: () { _isVideo = true; - _onImageButtonPressed(ImageSource.gallery, - context: context, allowMultiple: true); + _onImageButtonPressed( + ImageSource.gallery, + context: context, + allowMultiple: true, + ); }, heroTag: 'multiVideo', tooltip: 'Pick multiple videos', @@ -441,73 +462,87 @@ class _MyHomePageState extends State { } Future _displayPickImageDialog( - BuildContext context, OnPickImageCallback onPick) async { + BuildContext context, + OnPickImageCallback onPick, + ) async { return showDialog( - context: context, - builder: (BuildContext context) { - return AlertDialog( - title: const Text('Add optional parameters'), - content: Column( - children: [ - TextField( - controller: maxWidthController, - keyboardType: - const TextInputType.numberWithOptions(decimal: true), - decoration: const InputDecoration( - hintText: 'Enter maxWidth if desired'), + context: context, + builder: (BuildContext context) { + return AlertDialog( + title: const Text('Add optional parameters'), + content: Column( + children: [ + TextField( + controller: maxWidthController, + keyboardType: const TextInputType.numberWithOptions( + decimal: true, ), - TextField( - controller: maxHeightController, - keyboardType: - const TextInputType.numberWithOptions(decimal: true), - decoration: const InputDecoration( - hintText: 'Enter maxHeight if desired'), + decoration: const InputDecoration( + hintText: 'Enter maxWidth if desired', ), - TextField( - controller: qualityController, - keyboardType: TextInputType.number, - decoration: const InputDecoration( - hintText: 'Enter quality if desired'), + ), + TextField( + controller: maxHeightController, + keyboardType: const TextInputType.numberWithOptions( + decimal: true, + ), + decoration: const InputDecoration( + hintText: 'Enter maxHeight if desired', ), - ], - ), - actions: [ - TextButton( - child: const Text('CANCEL'), - onPressed: () { - Navigator.of(context).pop(); - }, ), - TextButton( - child: const Text('PICK'), - onPressed: () { - final double? width = maxWidthController.text.isNotEmpty + TextField( + controller: qualityController, + keyboardType: TextInputType.number, + decoration: const InputDecoration( + hintText: 'Enter quality if desired', + ), + ), + ], + ), + actions: [ + TextButton( + child: const Text('CANCEL'), + onPressed: () { + Navigator.of(context).pop(); + }, + ), + TextButton( + child: const Text('PICK'), + onPressed: () { + final double? width = + maxWidthController.text.isNotEmpty ? double.parse(maxWidthController.text) : null; - final double? height = maxHeightController.text.isNotEmpty + final double? height = + maxHeightController.text.isNotEmpty ? double.parse(maxHeightController.text) : null; - final int? quality = qualityController.text.isNotEmpty + final int? quality = + qualityController.text.isNotEmpty ? int.parse(qualityController.text) : null; - onPick(width, height, quality); - Navigator.of(context).pop(); - }), - ], - ); - }); + onPick(width, height, quality); + Navigator.of(context).pop(); + }, + ), + ], + ); + }, + ); } void _showPickedSnackBar(BuildContext context, List files) { - ScaffoldMessenger.of(context).showSnackBar(SnackBar( - content: Text('Picked: ${files.map((XFile it) => it.name).join(',')}'), - duration: const Duration(seconds: 2), - )); + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text('Picked: ${files.map((XFile it) => it.name).join(',')}'), + duration: const Duration(seconds: 2), + ), + ); } } -typedef OnPickImageCallback = void Function( - double? maxWidth, double? maxHeight, int? quality); +typedef OnPickImageCallback = + void Function(double? maxWidth, double? maxHeight, int? quality); class AspectRatioVideo extends StatefulWidget { const AspectRatioVideo(this.controller, {super.key}); diff --git a/packages/image_picker/image_picker_macos/example/pubspec.yaml b/packages/image_picker/image_picker_macos/example/pubspec.yaml index 4a61fe59517..de7bf253b28 100644 --- a/packages/image_picker/image_picker_macos/example/pubspec.yaml +++ b/packages/image_picker/image_picker_macos/example/pubspec.yaml @@ -4,8 +4,8 @@ publish_to: 'none' version: 1.0.0 environment: - sdk: ^3.6.0 - flutter: ">=3.27.0" + sdk: ^3.7.0 + flutter: ">=3.29.0" dependencies: flutter: diff --git a/packages/image_picker/image_picker_macos/lib/image_picker_macos.dart b/packages/image_picker/image_picker_macos/lib/image_picker_macos.dart index 9ca69f40a09..8ea4c42e0e3 100644 --- a/packages/image_picker/image_picker_macos/lib/image_picker_macos.dart +++ b/packages/image_picker/image_picker_macos/lib/image_picker_macos.dart @@ -35,11 +35,12 @@ class ImagePickerMacOS extends CameraDelegatingImagePickerPlatform { CameraDevice preferredCameraDevice = CameraDevice.rear, }) async { final XFile? file = await getImage( - source: source, - maxWidth: maxWidth, - maxHeight: maxHeight, - imageQuality: imageQuality, - preferredCameraDevice: preferredCameraDevice); + source: source, + maxWidth: maxWidth, + maxHeight: maxHeight, + imageQuality: imageQuality, + preferredCameraDevice: preferredCameraDevice, + ); if (file != null) { return PickedFile(file.path); } @@ -55,9 +56,10 @@ class ImagePickerMacOS extends CameraDelegatingImagePickerPlatform { Duration? maxDuration, }) async { final XFile? file = await getVideo( - source: source, - preferredCameraDevice: preferredCameraDevice, - maxDuration: maxDuration); + source: source, + preferredCameraDevice: preferredCameraDevice, + maxDuration: maxDuration, + ); if (file != null) { return PickedFile(file.path); } @@ -75,12 +77,14 @@ class ImagePickerMacOS extends CameraDelegatingImagePickerPlatform { CameraDevice preferredCameraDevice = CameraDevice.rear, }) async { return getImageFromSource( - source: source, - options: ImagePickerOptions( - maxWidth: maxWidth, - maxHeight: maxHeight, - imageQuality: imageQuality, - preferredCameraDevice: preferredCameraDevice)); + source: source, + options: ImagePickerOptions( + maxWidth: maxWidth, + maxHeight: maxHeight, + imageQuality: imageQuality, + preferredCameraDevice: preferredCameraDevice, + ), + ); } // [ImagePickerOptions] options are not currently supported. If any @@ -100,10 +104,12 @@ class ImagePickerMacOS extends CameraDelegatingImagePickerPlatform { // TODO(stuartmorgan): Add a native implementation that can use // PHPickerViewController on macOS 13+, with this as a fallback for // older OS versions: https://github.com/flutter/flutter/issues/125829. - const XTypeGroup typeGroup = - XTypeGroup(uniformTypeIdentifiers: ['public.image']); - final XFile? file = await fileSelector - .openFile(acceptedTypeGroups: [typeGroup]); + const XTypeGroup typeGroup = XTypeGroup( + uniformTypeIdentifiers: ['public.image'], + ); + final XFile? file = await fileSelector.openFile( + acceptedTypeGroups: [typeGroup], + ); return file; } // Ensure that there's a fallback in case a new source is added. @@ -126,14 +132,17 @@ class ImagePickerMacOS extends CameraDelegatingImagePickerPlatform { switch (source) { case ImageSource.camera: return super.getVideo( - source: source, - preferredCameraDevice: preferredCameraDevice, - maxDuration: maxDuration); + source: source, + preferredCameraDevice: preferredCameraDevice, + maxDuration: maxDuration, + ); case ImageSource.gallery: - const XTypeGroup typeGroup = - XTypeGroup(uniformTypeIdentifiers: ['public.movie']); - final XFile? file = await fileSelector - .openFile(acceptedTypeGroups: [typeGroup]); + const XTypeGroup typeGroup = XTypeGroup( + uniformTypeIdentifiers: ['public.movie'], + ); + final XFile? file = await fileSelector.openFile( + acceptedTypeGroups: [typeGroup], + ); return file; } // Ensure that there's a fallback in case a new source is added. @@ -153,24 +162,28 @@ class ImagePickerMacOS extends CameraDelegatingImagePickerPlatform { // TODO(stuartmorgan): Add a native implementation that can use // PHPickerViewController on macOS 13+, with this as a fallback for // older OS versions: https://github.com/flutter/flutter/issues/125829. - const XTypeGroup typeGroup = - XTypeGroup(uniformTypeIdentifiers: ['public.image']); - final List files = await fileSelector - .openFiles(acceptedTypeGroups: [typeGroup]); + const XTypeGroup typeGroup = XTypeGroup( + uniformTypeIdentifiers: ['public.image'], + ); + final List files = await fileSelector.openFiles( + acceptedTypeGroups: [typeGroup], + ); return files; } @override - Future> getMultiVideoWithOptions( - {MultiVideoPickerOptions options = - const MultiVideoPickerOptions()}) async { + Future> getMultiVideoWithOptions({ + MultiVideoPickerOptions options = const MultiVideoPickerOptions(), + }) async { // TODO(stuartmorgan): Add a native implementation that can use // PHPickerViewController on macOS 13+, with this as a fallback for // older OS versions: https://github.com/flutter/flutter/issues/125829. - const XTypeGroup typeGroup = - XTypeGroup(uniformTypeIdentifiers: ['public.movie']); - final List files = await fileSelector - .openFiles(acceptedTypeGroups: [typeGroup]); + const XTypeGroup typeGroup = XTypeGroup( + uniformTypeIdentifiers: ['public.movie'], + ); + final List files = await fileSelector.openFiles( + acceptedTypeGroups: [typeGroup], + ); return files; } @@ -180,20 +193,21 @@ class ImagePickerMacOS extends CameraDelegatingImagePickerPlatform { @override Future> getMedia({required MediaOptions options}) async { const XTypeGroup typeGroup = XTypeGroup( - label: 'images and videos', - extensions: ['public.image', 'public.movie']); + label: 'images and videos', + extensions: ['public.image', 'public.movie'], + ); List files; if (options.allowMultiple) { - files = await fileSelector - .openFiles(acceptedTypeGroups: [typeGroup]); + files = await fileSelector.openFiles( + acceptedTypeGroups: [typeGroup], + ); } else { - final XFile? file = await fileSelector - .openFile(acceptedTypeGroups: [typeGroup]); - files = [ - if (file != null) file, - ]; + final XFile? file = await fileSelector.openFile( + acceptedTypeGroups: [typeGroup], + ); + files = [if (file != null) file]; } return files; } diff --git a/packages/image_picker/image_picker_macos/pubspec.yaml b/packages/image_picker/image_picker_macos/pubspec.yaml index a9322ac481b..598517cd262 100644 --- a/packages/image_picker/image_picker_macos/pubspec.yaml +++ b/packages/image_picker/image_picker_macos/pubspec.yaml @@ -5,8 +5,8 @@ issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+ version: 0.2.2 environment: - sdk: ^3.6.0 - flutter: ">=3.27.0" + sdk: ^3.7.0 + flutter: ">=3.29.0" flutter: plugin: diff --git a/packages/image_picker/image_picker_macos/test/image_picker_macos_test.dart b/packages/image_picker/image_picker_macos/test/image_picker_macos_test.dart index ee8b473017a..ac4db3aecf9 100644 --- a/packages/image_picker/image_picker_macos/test/image_picker_macos_test.dart +++ b/packages/image_picker/image_picker_macos/test/image_picker_macos_test.dart @@ -28,13 +28,17 @@ void main() { plugin = ImagePickerMacOS(); mockFileSelectorPlatform = MockFileSelectorPlatform(); - when(mockFileSelectorPlatform.openFile( - acceptedTypeGroups: anyNamed('acceptedTypeGroups'))) - .thenAnswer((_) async => null); - - when(mockFileSelectorPlatform.openFiles( - acceptedTypeGroups: anyNamed('acceptedTypeGroups'))) - .thenAnswer((_) async => List.empty()); + when( + mockFileSelectorPlatform.openFile( + acceptedTypeGroups: anyNamed('acceptedTypeGroups'), + ), + ).thenAnswer((_) async => null); + + when( + mockFileSelectorPlatform.openFiles( + acceptedTypeGroups: anyNamed('acceptedTypeGroups'), + ), + ).thenAnswer((_) async => List.empty()); ImagePickerMacOS.fileSelector = mockFileSelectorPlatform; }); @@ -48,54 +52,75 @@ void main() { test('pickImage passes the accepted type groups correctly', () async { await plugin.pickImage(source: ImageSource.gallery); - final VerificationResult result = verify(mockFileSelectorPlatform - .openFile(acceptedTypeGroups: captureAnyNamed('acceptedTypeGroups'))); - expect(capturedTypeGroups(result)[0].uniformTypeIdentifiers, - ['public.image']); + final VerificationResult result = verify( + mockFileSelectorPlatform.openFile( + acceptedTypeGroups: captureAnyNamed('acceptedTypeGroups'), + ), + ); + expect(capturedTypeGroups(result)[0].uniformTypeIdentifiers, [ + 'public.image', + ]); }); test('getImage passes the accepted type groups correctly', () async { await plugin.getImage(source: ImageSource.gallery); - final VerificationResult result = verify(mockFileSelectorPlatform - .openFile(acceptedTypeGroups: captureAnyNamed('acceptedTypeGroups'))); - expect(capturedTypeGroups(result)[0].uniformTypeIdentifiers, - ['public.image']); + final VerificationResult result = verify( + mockFileSelectorPlatform.openFile( + acceptedTypeGroups: captureAnyNamed('acceptedTypeGroups'), + ), + ); + expect(capturedTypeGroups(result)[0].uniformTypeIdentifiers, [ + 'public.image', + ]); }); - test('getImageFromSource passes the accepted type groups correctly', - () async { - await plugin.getImageFromSource(source: ImageSource.gallery); + test( + 'getImageFromSource passes the accepted type groups correctly', + () async { + await plugin.getImageFromSource(source: ImageSource.gallery); - final VerificationResult result = verify(mockFileSelectorPlatform - .openFile(acceptedTypeGroups: captureAnyNamed('acceptedTypeGroups'))); - expect(capturedTypeGroups(result)[0].uniformTypeIdentifiers, - ['public.image']); - }); + final VerificationResult result = verify( + mockFileSelectorPlatform.openFile( + acceptedTypeGroups: captureAnyNamed('acceptedTypeGroups'), + ), + ); + expect(capturedTypeGroups(result)[0].uniformTypeIdentifiers, [ + 'public.image', + ]); + }, + ); test('getImageFromSource calls delegate when source is camera', () async { const String fakePath = '/tmp/foo'; plugin.cameraDelegate = FakeCameraDelegate(result: XFile(fakePath)); expect( - (await plugin.getImageFromSource(source: ImageSource.camera))!.path, - fakePath); + (await plugin.getImageFromSource(source: ImageSource.camera))!.path, + fakePath, + ); }); test( - 'getImageFromSource throws StateError when source is camera with no delegate', - () async { - await expectLater(plugin.getImageFromSource(source: ImageSource.camera), - throwsStateError); - }); + 'getImageFromSource throws StateError when source is camera with no delegate', + () async { + await expectLater( + plugin.getImageFromSource(source: ImageSource.camera), + throwsStateError, + ); + }, + ); test('getMultiImage passes the accepted type groups correctly', () async { await plugin.getMultiImage(); final VerificationResult result = verify( - mockFileSelectorPlatform.openFiles( - acceptedTypeGroups: captureAnyNamed('acceptedTypeGroups'))); - expect(capturedTypeGroups(result)[0].uniformTypeIdentifiers, - ['public.image']); + mockFileSelectorPlatform.openFiles( + acceptedTypeGroups: captureAnyNamed('acceptedTypeGroups'), + ), + ); + expect(capturedTypeGroups(result)[0].uniformTypeIdentifiers, [ + 'public.image', + ]); }); }); @@ -103,44 +128,63 @@ void main() { test('pickVideo passes the accepted type groups correctly', () async { await plugin.pickVideo(source: ImageSource.gallery); - final VerificationResult result = verify(mockFileSelectorPlatform - .openFile(acceptedTypeGroups: captureAnyNamed('acceptedTypeGroups'))); - expect(capturedTypeGroups(result)[0].uniformTypeIdentifiers, - ['public.movie']); + final VerificationResult result = verify( + mockFileSelectorPlatform.openFile( + acceptedTypeGroups: captureAnyNamed('acceptedTypeGroups'), + ), + ); + expect(capturedTypeGroups(result)[0].uniformTypeIdentifiers, [ + 'public.movie', + ]); }); test('getVideo passes the accepted type groups correctly', () async { await plugin.getVideo(source: ImageSource.gallery); - final VerificationResult result = verify(mockFileSelectorPlatform - .openFile(acceptedTypeGroups: captureAnyNamed('acceptedTypeGroups'))); - expect(capturedTypeGroups(result)[0].uniformTypeIdentifiers, - ['public.movie']); + final VerificationResult result = verify( + mockFileSelectorPlatform.openFile( + acceptedTypeGroups: captureAnyNamed('acceptedTypeGroups'), + ), + ); + expect(capturedTypeGroups(result)[0].uniformTypeIdentifiers, [ + 'public.movie', + ]); }); test('getVideo calls delegate when source is camera', () async { const String fakePath = '/tmp/foo'; plugin.cameraDelegate = FakeCameraDelegate(result: XFile(fakePath)); expect( - (await plugin.getVideo(source: ImageSource.camera))!.path, fakePath); + (await plugin.getVideo(source: ImageSource.camera))!.path, + fakePath, + ); }); - test('getVideo throws StateError when source is camera with no delegate', - () async { - await expectLater( - plugin.getVideo(source: ImageSource.camera), throwsStateError); - }); + test( + 'getVideo throws StateError when source is camera with no delegate', + () async { + await expectLater( + plugin.getVideo(source: ImageSource.camera), + throwsStateError, + ); + }, + ); - test('getMultiVideoWithOptions passes the accepted type groups correctly', - () async { - await plugin.getMultiVideoWithOptions(); + test( + 'getMultiVideoWithOptions passes the accepted type groups correctly', + () async { + await plugin.getMultiVideoWithOptions(); - final VerificationResult result = verify( + final VerificationResult result = verify( mockFileSelectorPlatform.openFiles( - acceptedTypeGroups: captureAnyNamed('acceptedTypeGroups'))); - expect(capturedTypeGroups(result)[0].uniformTypeIdentifiers, - ['public.movie']); - }); + acceptedTypeGroups: captureAnyNamed('acceptedTypeGroups'), + ), + ); + expect(capturedTypeGroups(result)[0].uniformTypeIdentifiers, [ + 'public.movie', + ]); + }, + ); }); group('media', () { @@ -148,30 +192,30 @@ void main() { await plugin.getMedia(options: const MediaOptions(allowMultiple: true)); final VerificationResult result = verify( - mockFileSelectorPlatform.openFiles( - acceptedTypeGroups: captureAnyNamed('acceptedTypeGroups'))); - expect(capturedTypeGroups(result)[0].extensions, - ['public.image', 'public.movie']); + mockFileSelectorPlatform.openFiles( + acceptedTypeGroups: captureAnyNamed('acceptedTypeGroups'), + ), + ); + expect(capturedTypeGroups(result)[0].extensions, [ + 'public.image', + 'public.movie', + ]); }); test('multiple media handles an empty path response gracefully', () async { expect( - await plugin.getMedia( - options: const MediaOptions( - allowMultiple: true, - ), - ), - []); + await plugin.getMedia(options: const MediaOptions(allowMultiple: true)), + [], + ); }); test('single media handles an empty path response gracefully', () async { expect( - await plugin.getMedia( - options: const MediaOptions( - allowMultiple: false, - ), - ), - []); + await plugin.getMedia( + options: const MediaOptions(allowMultiple: false), + ), + [], + ); }); }); } @@ -182,16 +226,18 @@ class FakeCameraDelegate extends ImagePickerCameraDelegate { XFile? result; @override - Future takePhoto( - {ImagePickerCameraDelegateOptions options = - const ImagePickerCameraDelegateOptions()}) async { + Future takePhoto({ + ImagePickerCameraDelegateOptions options = + const ImagePickerCameraDelegateOptions(), + }) async { return result; } @override - Future takeVideo( - {ImagePickerCameraDelegateOptions options = - const ImagePickerCameraDelegateOptions()}) async { + Future takeVideo({ + ImagePickerCameraDelegateOptions options = + const ImagePickerCameraDelegateOptions(), + }) async { return result; } } diff --git a/packages/image_picker/image_picker_macos/test/image_picker_macos_test.mocks.dart b/packages/image_picker/image_picker_macos/test/image_picker_macos_test.mocks.dart index 0887befdb0b..9b03fe8feb3 100644 --- a/packages/image_picker/image_picker_macos/test/image_picker_macos_test.mocks.dart +++ b/packages/image_picker/image_picker_macos/test/image_picker_macos_test.mocks.dart @@ -38,17 +38,14 @@ class MockFileSelectorPlatform extends _i1.Mock String? confirmButtonText, }) => (super.noSuchMethod( - Invocation.method( - #openFile, - [], - { - #acceptedTypeGroups: acceptedTypeGroups, - #initialDirectory: initialDirectory, - #confirmButtonText: confirmButtonText, - }, - ), - returnValue: _i3.Future<_i2.XFile?>.value(), - ) as _i3.Future<_i2.XFile?>); + Invocation.method(#openFile, [], { + #acceptedTypeGroups: acceptedTypeGroups, + #initialDirectory: initialDirectory, + #confirmButtonText: confirmButtonText, + }), + returnValue: _i3.Future<_i2.XFile?>.value(), + ) + as _i3.Future<_i2.XFile?>); @override _i3.Future> openFiles({ @@ -57,17 +54,14 @@ class MockFileSelectorPlatform extends _i1.Mock String? confirmButtonText, }) => (super.noSuchMethod( - Invocation.method( - #openFiles, - [], - { - #acceptedTypeGroups: acceptedTypeGroups, - #initialDirectory: initialDirectory, - #confirmButtonText: confirmButtonText, - }, - ), - returnValue: _i3.Future>.value(<_i2.XFile>[]), - ) as _i3.Future>); + Invocation.method(#openFiles, [], { + #acceptedTypeGroups: acceptedTypeGroups, + #initialDirectory: initialDirectory, + #confirmButtonText: confirmButtonText, + }), + returnValue: _i3.Future>.value(<_i2.XFile>[]), + ) + as _i3.Future>); @override _i3.Future getSavePath({ @@ -77,18 +71,15 @@ class MockFileSelectorPlatform extends _i1.Mock String? confirmButtonText, }) => (super.noSuchMethod( - Invocation.method( - #getSavePath, - [], - { - #acceptedTypeGroups: acceptedTypeGroups, - #initialDirectory: initialDirectory, - #suggestedName: suggestedName, - #confirmButtonText: confirmButtonText, - }, - ), - returnValue: _i3.Future.value(), - ) as _i3.Future); + Invocation.method(#getSavePath, [], { + #acceptedTypeGroups: acceptedTypeGroups, + #initialDirectory: initialDirectory, + #suggestedName: suggestedName, + #confirmButtonText: confirmButtonText, + }), + returnValue: _i3.Future.value(), + ) + as _i3.Future); @override _i3.Future<_i2.FileSaveLocation?> getSaveLocation({ @@ -96,16 +87,13 @@ class MockFileSelectorPlatform extends _i1.Mock _i2.SaveDialogOptions? options = const _i2.SaveDialogOptions(), }) => (super.noSuchMethod( - Invocation.method( - #getSaveLocation, - [], - { - #acceptedTypeGroups: acceptedTypeGroups, - #options: options, - }, - ), - returnValue: _i3.Future<_i2.FileSaveLocation?>.value(), - ) as _i3.Future<_i2.FileSaveLocation?>); + Invocation.method(#getSaveLocation, [], { + #acceptedTypeGroups: acceptedTypeGroups, + #options: options, + }), + returnValue: _i3.Future<_i2.FileSaveLocation?>.value(), + ) + as _i3.Future<_i2.FileSaveLocation?>); @override _i3.Future getDirectoryPath({ @@ -113,16 +101,13 @@ class MockFileSelectorPlatform extends _i1.Mock String? confirmButtonText, }) => (super.noSuchMethod( - Invocation.method( - #getDirectoryPath, - [], - { - #initialDirectory: initialDirectory, - #confirmButtonText: confirmButtonText, - }, - ), - returnValue: _i3.Future.value(), - ) as _i3.Future); + Invocation.method(#getDirectoryPath, [], { + #initialDirectory: initialDirectory, + #confirmButtonText: confirmButtonText, + }), + returnValue: _i3.Future.value(), + ) + as _i3.Future); @override _i3.Future> getDirectoryPaths({ @@ -130,14 +115,11 @@ class MockFileSelectorPlatform extends _i1.Mock String? confirmButtonText, }) => (super.noSuchMethod( - Invocation.method( - #getDirectoryPaths, - [], - { - #initialDirectory: initialDirectory, - #confirmButtonText: confirmButtonText, - }, - ), - returnValue: _i3.Future>.value([]), - ) as _i3.Future>); + Invocation.method(#getDirectoryPaths, [], { + #initialDirectory: initialDirectory, + #confirmButtonText: confirmButtonText, + }), + returnValue: _i3.Future>.value([]), + ) + as _i3.Future>); } diff --git a/packages/image_picker/image_picker_platform_interface/CHANGELOG.md b/packages/image_picker/image_picker_platform_interface/CHANGELOG.md index c87ceb07905..e3007e98fc9 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 @@ +## NEXT + +* Updates minimum supported SDK version to Flutter 3.29/Dart 3.7. + ## 2.11.0 * Adds `getMultiVideoWithOptions` method. 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 943ea760995..333eebba5ea 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 @@ -62,7 +62,10 @@ class MethodChannelImagePicker extends ImagePickerPlatform { }) { if (imageQuality != null && (imageQuality < 0 || imageQuality > 100)) { throw ArgumentError.value( - imageQuality, 'imageQuality', 'must be between 0 and 100'); + imageQuality, + 'imageQuality', + 'must be between 0 and 100', + ); } if (maxWidth != null && maxWidth < 0) { @@ -73,16 +76,14 @@ class MethodChannelImagePicker extends ImagePickerPlatform { throw ArgumentError.value(maxHeight, 'maxHeight', 'cannot be negative'); } - return _channel.invokeMethod?>( - 'pickMultiImage', - { - 'maxWidth': maxWidth, - 'maxHeight': maxHeight, - 'imageQuality': imageQuality, - 'requestFullMetadata': requestFullMetadata, - 'limit': limit, - }, - ); + return _channel + .invokeMethod?>('pickMultiImage', { + 'maxWidth': maxWidth, + 'maxHeight': maxHeight, + 'imageQuality': imageQuality, + 'requestFullMetadata': requestFullMetadata, + 'limit': limit, + }); } Future _getImagePath({ @@ -95,7 +96,10 @@ class MethodChannelImagePicker extends ImagePickerPlatform { }) { if (imageQuality != null && (imageQuality < 0 || imageQuality > 100)) { throw ArgumentError.value( - imageQuality, 'imageQuality', 'must be between 0 and 100'); + imageQuality, + 'imageQuality', + 'must be between 0 and 100', + ); } if (maxWidth != null && maxWidth < 0) { @@ -106,17 +110,14 @@ class MethodChannelImagePicker extends ImagePickerPlatform { throw ArgumentError.value(maxHeight, 'maxHeight', 'cannot be negative'); } - return _channel.invokeMethod( - 'pickImage', - { - 'source': source.index, - 'maxWidth': maxWidth, - 'maxHeight': maxHeight, - 'imageQuality': imageQuality, - 'cameraDevice': preferredCameraDevice.index, - 'requestFullMetadata': requestFullMetadata, - }, - ); + return _channel.invokeMethod('pickImage', { + 'source': source.index, + 'maxWidth': maxWidth, + 'maxHeight': maxHeight, + 'imageQuality': imageQuality, + 'cameraDevice': preferredCameraDevice.index, + 'requestFullMetadata': requestFullMetadata, + }); } @override @@ -138,20 +139,17 @@ class MethodChannelImagePicker extends ImagePickerPlatform { CameraDevice preferredCameraDevice = CameraDevice.rear, Duration? maxDuration, }) { - return _channel.invokeMethod( - 'pickVideo', - { - 'source': source.index, - 'maxDuration': maxDuration?.inSeconds, - 'cameraDevice': preferredCameraDevice.index - }, - ); + return _channel.invokeMethod('pickVideo', { + 'source': source.index, + 'maxDuration': maxDuration?.inSeconds, + 'cameraDevice': preferredCameraDevice.index, + }); } @override Future retrieveLostData() async { - final Map? result = - await _channel.invokeMapMethod('retrieve'); + final Map? result = await _channel + .invokeMapMethod('retrieve'); if (result == null) { return LostData.empty(); @@ -172,8 +170,9 @@ class MethodChannelImagePicker extends ImagePickerPlatform { PlatformException? exception; if (result.containsKey('errorCode')) { exception = PlatformException( - code: result['errorCode']! as String, - message: result['errorMessage'] as String?); + code: result['errorCode']! as String, + message: result['errorMessage'] as String?, + ); } final String? path = result['path'] as String?; @@ -256,9 +255,7 @@ class MethodChannelImagePicker extends ImagePickerPlatform { } @override - Future> getMedia({ - required MediaOptions options, - }) async { + Future> getMedia({required MediaOptions options}) async { final ImageOptions imageOptions = options.imageOptions; final Map args = { @@ -270,12 +267,11 @@ class MethodChannelImagePicker extends ImagePickerPlatform { }; final List? paths = await _channel - .invokeMethod?>( - 'pickMedia', - args, - ) - .then((List? paths) => - paths?.map((dynamic path) => XFile(path as String)).toList()); + .invokeMethod?>('pickMedia', args) + .then( + (List? paths) => + paths?.map((dynamic path) => XFile(path as String)).toList(), + ); return paths ?? []; } @@ -298,8 +294,8 @@ class MethodChannelImagePicker extends ImagePickerPlatform { Future getLostData() async { List? pickedFileList; - final Map? result = - await _channel.invokeMapMethod('retrieve'); + final Map? result = await _channel + .invokeMapMethod('retrieve'); if (result == null) { return LostDataResponse.empty(); @@ -308,9 +304,7 @@ class MethodChannelImagePicker extends ImagePickerPlatform { assert(result.containsKey('path') != result.containsKey('errorCode')); final String? type = result['type'] as String?; - assert( - type == kTypeImage || type == kTypeVideo || type == kTypeMedia, - ); + assert(type == kTypeImage || type == kTypeVideo || type == kTypeMedia); RetrieveType? retrieveType; switch (type) { @@ -325,8 +319,9 @@ class MethodChannelImagePicker extends ImagePickerPlatform { PlatformException? exception; if (result.containsKey('errorCode')) { exception = PlatformException( - code: result['errorCode']! as String, - message: result['errorMessage'] as String?); + code: result['errorCode']! as String, + message: result['errorMessage'] as String?, + ); } final String? path = result['path'] as String?; 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 51074c864b2..31519d3a164 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 @@ -225,9 +225,7 @@ abstract class ImagePickerPlatform extends PlatformInterface { /// call [getLostData] when your app relaunches to retrieve the lost data. /// /// If no images or videos were picked, the return value is an empty list. - Future> getMedia({ - required MediaOptions options, - }) { + Future> getMedia({required MediaOptions options}) { throw UnimplementedError('getMedia() has not been implemented.'); } @@ -334,7 +332,8 @@ abstract class ImagePickerPlatform extends PlatformInterface { MultiVideoPickerOptions options = const MultiVideoPickerOptions(), }) { throw UnimplementedError( - 'getMultiVideoWithOptions() has not been implemented.'); + 'getMultiVideoWithOptions() has not been implemented.', + ); } /// Returns true if the implementation supports [source]. @@ -373,13 +372,15 @@ abstract class CameraDelegatingImagePickerPlatform extends ImagePickerPlatform { final ImagePickerCameraDelegate? delegate = cameraDelegate; if (delegate == null) { throw StateError( - 'This implementation of ImagePickerPlatform requires a ' - '"cameraDelegate" in order to use ImageSource.camera'); + 'This implementation of ImagePickerPlatform requires a ' + '"cameraDelegate" in order to use ImageSource.camera', + ); } return delegate.takePhoto( - options: ImagePickerCameraDelegateOptions( - preferredCameraDevice: options.preferredCameraDevice, - )); + options: ImagePickerCameraDelegateOptions( + preferredCameraDevice: options.preferredCameraDevice, + ), + ); } return super.getImageFromSource(source: source, options: options); } @@ -394,17 +395,21 @@ abstract class CameraDelegatingImagePickerPlatform extends ImagePickerPlatform { final ImagePickerCameraDelegate? delegate = cameraDelegate; if (delegate == null) { throw StateError( - 'This implementation of ImagePickerPlatform requires a ' - '"cameraDelegate" in order to use ImageSource.camera'); + 'This implementation of ImagePickerPlatform requires a ' + '"cameraDelegate" in order to use ImageSource.camera', + ); } return delegate.takeVideo( - options: ImagePickerCameraDelegateOptions( - preferredCameraDevice: preferredCameraDevice, - maxVideoDuration: maxDuration)); + options: ImagePickerCameraDelegateOptions( + preferredCameraDevice: preferredCameraDevice, + maxVideoDuration: maxDuration, + ), + ); } return super.getVideo( - source: source, - preferredCameraDevice: preferredCameraDevice, - maxDuration: maxDuration); + source: source, + preferredCameraDevice: preferredCameraDevice, + maxDuration: maxDuration, + ); } } diff --git a/packages/image_picker/image_picker_platform_interface/lib/src/types/image_options.dart b/packages/image_picker/image_picker_platform_interface/lib/src/types/image_options.dart index 374ff27063f..31221a28d93 100644 --- a/packages/image_picker/image_picker_platform_interface/lib/src/types/image_options.dart +++ b/packages/image_picker/image_picker_platform_interface/lib/src/types/image_options.dart @@ -56,7 +56,10 @@ class ImageOptions { this.requestFullMetadata = true, }) { _validateOptions( - maxWidth: maxWidth, maxHeight: maxHeight, imageQuality: imageQuality); + maxWidth: maxWidth, + maxHeight: maxHeight, + imageQuality: imageQuality, + ); } /// The maximum width of the image, in pixels. @@ -86,11 +89,17 @@ class ImageOptions { final bool requestFullMetadata; /// Validates that all values are within required ranges. Throws if not. - static void _validateOptions( - {double? maxWidth, final double? maxHeight, int? imageQuality}) { + static void _validateOptions({ + double? maxWidth, + final double? maxHeight, + int? imageQuality, + }) { if (imageQuality != null && (imageQuality < 0 || imageQuality > 100)) { throw ArgumentError.value( - imageQuality, 'imageQuality', 'must be between 0 and 100'); + imageQuality, + 'imageQuality', + 'must be between 0 and 100', + ); } if (maxWidth != null && maxWidth < 0) { throw ArgumentError.value(maxWidth, 'maxWidth', 'cannot be negative'); diff --git a/packages/image_picker/image_picker_platform_interface/lib/src/types/lost_data_response.dart b/packages/image_picker/image_picker_platform_interface/lib/src/types/lost_data_response.dart index 0f802f19719..ac3ce403550 100644 --- a/packages/image_picker/image_picker_platform_interface/lib/src/types/lost_data_response.dart +++ b/packages/image_picker/image_picker_platform_interface/lib/src/types/lost_data_response.dart @@ -15,21 +15,16 @@ import 'types.dart'; class LostDataResponse { /// Creates an instance with the given [file], [exception], and [type]. Any of /// the params may be null, but this is never considered to be empty. - LostDataResponse({ - this.file, - this.exception, - this.type, - this.files, - }); + LostDataResponse({this.file, this.exception, this.type, this.files}); /// Initializes an instance with all member params set to null and considered /// to be empty. LostDataResponse.empty() - : file = null, - exception = null, - type = null, - _empty = true, - files = null; + : file = null, + exception = null, + type = null, + _empty = true, + files = null; /// Whether it is an empty response. /// diff --git a/packages/image_picker/image_picker_platform_interface/lib/src/types/multi_video_picker_options.dart b/packages/image_picker/image_picker_platform_interface/lib/src/types/multi_video_picker_options.dart index 66149b9c3d3..9779efcfa28 100644 --- a/packages/image_picker/image_picker_platform_interface/lib/src/types/multi_video_picker_options.dart +++ b/packages/image_picker/image_picker_platform_interface/lib/src/types/multi_video_picker_options.dart @@ -8,10 +8,7 @@ import 'package:flutter/foundation.dart'; @immutable class MultiVideoPickerOptions { /// Creates an instance with the given options. - const MultiVideoPickerOptions({ - this.maxDuration, - this.limit, - }); + const MultiVideoPickerOptions({this.maxDuration, this.limit}); /// The maximum duration of the picked video. final Duration? maxDuration; diff --git a/packages/image_picker/image_picker_platform_interface/lib/src/types/picked_file/html.dart b/packages/image_picker/image_picker_platform_interface/lib/src/types/picked_file/html.dart index e296ceb9d80..8f1bb54cd9b 100644 --- a/packages/image_picker/image_picker_platform_interface/lib/src/types/picked_file/html.dart +++ b/packages/image_picker/image_picker_platform_interface/lib/src/types/picked_file/html.dart @@ -18,8 +18,8 @@ class PickedFile extends PickedFileBase { /// Optionally, this can be initialized with `bytes` /// so no http requests are performed to retrieve files later. const PickedFile(this.path, {Uint8List? bytes}) - : _initBytes = bytes, - super(path); + : _initBytes = bytes, + super(path); @override final String path; diff --git a/packages/image_picker/image_picker_platform_interface/lib/src/types/picked_file/lost_data.dart b/packages/image_picker/image_picker_platform_interface/lib/src/types/picked_file/lost_data.dart index ddd36b62c02..bc0895194c1 100644 --- a/packages/image_picker/image_picker_platform_interface/lib/src/types/picked_file/lost_data.dart +++ b/packages/image_picker/image_picker_platform_interface/lib/src/types/picked_file/lost_data.dart @@ -18,11 +18,7 @@ class LostData { /// Initializes an instance with all member params set to null and considered /// to be empty. - LostData.empty() - : file = null, - exception = null, - type = null, - _empty = true; + LostData.empty() : file = null, exception = null, type = null, _empty = true; /// Whether it is an empty response. /// diff --git a/packages/image_picker/image_picker_platform_interface/lib/src/types/picked_file/unsupported.dart b/packages/image_picker/image_picker_platform_interface/lib/src/types/picked_file/unsupported.dart index a98846c3c4c..e52d8a985fb 100644 --- a/packages/image_picker/image_picker_platform_interface/lib/src/types/picked_file/unsupported.dart +++ b/packages/image_picker/image_picker_platform_interface/lib/src/types/picked_file/unsupported.dart @@ -13,6 +13,7 @@ class PickedFile extends PickedFileBase { /// Optionally, you may pass a `path`. See caveats in [PickedFileBase.path]. PickedFile(super.path) { throw UnimplementedError( - 'PickedFile is not available in your current platform.'); + 'PickedFile is not available in your current platform.', + ); } } diff --git a/packages/image_picker/image_picker_platform_interface/pubspec.yaml b/packages/image_picker/image_picker_platform_interface/pubspec.yaml index 1ebf4ebd08e..a5cb4ab500d 100644 --- a/packages/image_picker/image_picker_platform_interface/pubspec.yaml +++ b/packages/image_picker/image_picker_platform_interface/pubspec.yaml @@ -7,8 +7,8 @@ issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+ version: 2.11.0 environment: - sdk: ^3.6.0 - flutter: ">=3.27.0" + sdk: ^3.7.0 + flutter: ">=3.29.0" dependencies: cross_file: ^0.3.1+1 diff --git a/packages/image_picker/image_picker_platform_interface/test/image_picker_platform_test.dart b/packages/image_picker/image_picker_platform_interface/test/image_picker_platform_test.dart index c25f7ae9fe5..e269efe2681 100644 --- a/packages/image_picker/image_picker_platform_interface/test/image_picker_platform_test.dart +++ b/packages/image_picker/image_picker_platform_interface/test/image_picker_platform_test.dart @@ -17,68 +17,81 @@ void main() { group('CameraDelegatingImagePickerPlatform', () { test( - 'supportsImageSource returns false for camera when there is no delegate', - () async { - final FakeCameraDelegatingImagePickerPlatform implementation = - FakeCameraDelegatingImagePickerPlatform(); + 'supportsImageSource returns false for camera when there is no delegate', + () async { + final FakeCameraDelegatingImagePickerPlatform implementation = + FakeCameraDelegatingImagePickerPlatform(); - expect(implementation.supportsImageSource(ImageSource.camera), false); - }); - - test('supportsImageSource returns true for camera when there is a delegate', - () async { - final FakeCameraDelegatingImagePickerPlatform implementation = - FakeCameraDelegatingImagePickerPlatform(); - implementation.cameraDelegate = FakeCameraDelegate(); + expect(implementation.supportsImageSource(ImageSource.camera), false); + }, + ); - expect(implementation.supportsImageSource(ImageSource.camera), true); - }); + test( + 'supportsImageSource returns true for camera when there is a delegate', + () async { + final FakeCameraDelegatingImagePickerPlatform implementation = + FakeCameraDelegatingImagePickerPlatform(); + implementation.cameraDelegate = FakeCameraDelegate(); + + expect(implementation.supportsImageSource(ImageSource.camera), true); + }, + ); - test('getImageFromSource for camera throws if delegate is not set', - () async { - final FakeCameraDelegatingImagePickerPlatform implementation = - FakeCameraDelegatingImagePickerPlatform(); + test( + 'getImageFromSource for camera throws if delegate is not set', + () async { + final FakeCameraDelegatingImagePickerPlatform implementation = + FakeCameraDelegatingImagePickerPlatform(); - await expectLater( + await expectLater( implementation.getImageFromSource(source: ImageSource.camera), - throwsStateError); - }); + throwsStateError, + ); + }, + ); test('getVideo for camera throws if delegate is not set', () async { final FakeCameraDelegatingImagePickerPlatform implementation = FakeCameraDelegatingImagePickerPlatform(); - await expectLater(implementation.getVideo(source: ImageSource.camera), - throwsStateError); + await expectLater( + implementation.getVideo(source: ImageSource.camera), + throwsStateError, + ); }); test('getImageFromSource for camera calls delegate if set', () async { const String fakePath = '/tmp/foo'; final FakeCameraDelegatingImagePickerPlatform implementation = FakeCameraDelegatingImagePickerPlatform(); - implementation.cameraDelegate = - FakeCameraDelegate(result: XFile(fakePath)); + implementation.cameraDelegate = FakeCameraDelegate( + result: XFile(fakePath), + ); expect( - (await implementation.getImageFromSource(source: ImageSource.camera))! - .path, - fakePath); + (await implementation.getImageFromSource( + source: ImageSource.camera, + ))!.path, + fakePath, + ); }); test('getVideo for camera calls delegate if set', () async { const String fakePath = '/tmp/foo'; final FakeCameraDelegatingImagePickerPlatform implementation = FakeCameraDelegatingImagePickerPlatform(); - implementation.cameraDelegate = - FakeCameraDelegate(result: XFile(fakePath)); + implementation.cameraDelegate = FakeCameraDelegate( + result: XFile(fakePath), + ); - expect((await implementation.getVideo(source: ImageSource.camera))!.path, - fakePath); + expect( + (await implementation.getVideo(source: ImageSource.camera))!.path, + fakePath, + ); }); }); - test( - 'Default implementation of getMultiVideoWithOptions should throw ' + test('Default implementation of getMultiVideoWithOptions should throw ' 'unimplemented error', () { final FakeCameraDelegatingImagePickerPlatform implementation = FakeCameraDelegatingImagePickerPlatform(); @@ -101,16 +114,18 @@ class FakeCameraDelegate extends ImagePickerCameraDelegate { XFile? result; @override - Future takePhoto( - {ImagePickerCameraDelegateOptions options = - const ImagePickerCameraDelegateOptions()}) async { + Future takePhoto({ + ImagePickerCameraDelegateOptions options = + const ImagePickerCameraDelegateOptions(), + }) async { return result; } @override - Future takeVideo( - {ImagePickerCameraDelegateOptions options = - const ImagePickerCameraDelegateOptions()}) async { + Future takeVideo({ + ImagePickerCameraDelegateOptions options = + const ImagePickerCameraDelegateOptions(), + }) async { return result; } } diff --git a/packages/image_picker/image_picker_platform_interface/test/media_options_test.dart b/packages/image_picker/image_picker_platform_interface/test/media_options_test.dart index 44a5f58c8cb..dcd6ca28d8b 100644 --- a/packages/image_picker/image_picker_platform_interface/test/media_options_test.dart +++ b/packages/image_picker/image_picker_platform_interface/test/media_options_test.dart @@ -43,12 +43,13 @@ void main() { }); test( - 'createAndValidate throw error when allowMultiple is false and has limit', - () { - expect( - () => MediaOptions.createAndValidate(allowMultiple: false, limit: 2), - throwsArgumentError, - ); - }); + 'createAndValidate throw error when allowMultiple is false and has limit', + () { + expect( + () => MediaOptions.createAndValidate(allowMultiple: false, limit: 2), + throwsArgumentError, + ); + }, + ); }); } diff --git a/packages/image_picker/image_picker_platform_interface/test/method_channel_image_picker_test.dart b/packages/image_picker/image_picker_platform_interface/test/method_channel_image_picker_test.dart index abc69671101..6de773a0cfd 100644 --- a/packages/image_picker/image_picker_platform_interface/test/method_channel_image_picker_test.dart +++ b/packages/image_picker/image_picker_platform_interface/test/method_channel_image_picker_test.dart @@ -19,11 +19,12 @@ void main() { setUp(() { returnValue = ''; TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger - .setMockMethodCallHandler(picker.channel, - (MethodCall methodCall) async { - log.add(methodCall); - return returnValue; - }); + .setMockMethodCallHandler(picker.channel, ( + MethodCall methodCall, + ) async { + log.add(methodCall); + return returnValue; + }); log.clear(); }); @@ -33,39 +34,36 @@ void main() { await picker.pickImage(source: ImageSource.camera); await picker.pickImage(source: ImageSource.gallery); - expect( - log, - [ - isMethodCall('pickImage', arguments: { + expect(log, [ + isMethodCall( + 'pickImage', + arguments: { 'source': 0, 'maxWidth': null, 'maxHeight': null, 'imageQuality': null, 'cameraDevice': 0, 'requestFullMetadata': true, - }), - isMethodCall('pickImage', arguments: { + }, + ), + isMethodCall( + 'pickImage', + arguments: { 'source': 1, 'maxWidth': null, 'maxHeight': null, 'imageQuality': null, 'cameraDevice': 0, 'requestFullMetadata': true, - }), - ], - ); + }, + ), + ]); }); 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, - ); + await picker.pickImage(source: ImageSource.camera, maxWidth: 10.0); + await picker.pickImage(source: ImageSource.camera, maxHeight: 10.0); await picker.pickImage( source: ImageSource.camera, maxWidth: 10.0, @@ -88,67 +86,85 @@ void main() { imageQuality: 70, ); - expect( - log, - [ - isMethodCall('pickImage', arguments: { + expect(log, [ + isMethodCall( + 'pickImage', + arguments: { 'source': 0, 'maxWidth': null, 'maxHeight': null, 'imageQuality': null, 'cameraDevice': 0, 'requestFullMetadata': true, - }), - isMethodCall('pickImage', arguments: { + }, + ), + isMethodCall( + 'pickImage', + arguments: { 'source': 0, 'maxWidth': 10.0, 'maxHeight': null, 'imageQuality': null, 'cameraDevice': 0, 'requestFullMetadata': true, - }), - isMethodCall('pickImage', arguments: { + }, + ), + isMethodCall( + 'pickImage', + arguments: { 'source': 0, 'maxWidth': null, 'maxHeight': 10.0, 'imageQuality': null, 'cameraDevice': 0, 'requestFullMetadata': true, - }), - isMethodCall('pickImage', arguments: { + }, + ), + isMethodCall( + 'pickImage', + arguments: { 'source': 0, 'maxWidth': 10.0, 'maxHeight': 20.0, 'imageQuality': null, 'cameraDevice': 0, 'requestFullMetadata': true, - }), - isMethodCall('pickImage', arguments: { + }, + ), + isMethodCall( + 'pickImage', + arguments: { 'source': 0, 'maxWidth': 10.0, 'maxHeight': null, 'imageQuality': 70, 'cameraDevice': 0, 'requestFullMetadata': true, - }), - isMethodCall('pickImage', arguments: { + }, + ), + isMethodCall( + 'pickImage', + arguments: { 'source': 0, 'maxWidth': null, 'maxHeight': 10.0, 'imageQuality': 70, 'cameraDevice': 0, 'requestFullMetadata': true, - }), - isMethodCall('pickImage', arguments: { + }, + ), + isMethodCall( + 'pickImage', + arguments: { 'source': 0, 'maxWidth': 10.0, 'maxHeight': 20.0, 'imageQuality': 70, 'cameraDevice': 0, 'requestFullMetadata': true, - }), - ], - ); + }, + ), + ]); }); test('does not accept an invalid imageQuality argument', () { @@ -189,7 +205,9 @@ void main() { test('handles a null image path response gracefully', () async { TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger .setMockMethodCallHandler( - picker.channel, (MethodCall methodCall) => null); + picker.channel, + (MethodCall methodCall) => null, + ); expect(await picker.pickImage(source: ImageSource.gallery), isNull); expect(await picker.pickImage(source: ImageSource.camera), isNull); @@ -198,39 +216,40 @@ void main() { test('camera position defaults to back', () async { await picker.pickImage(source: ImageSource.camera); - expect( - log, - [ - isMethodCall('pickImage', arguments: { + expect(log, [ + isMethodCall( + 'pickImage', + arguments: { 'source': 0, 'maxWidth': null, 'maxHeight': null, 'imageQuality': null, 'cameraDevice': 0, 'requestFullMetadata': true, - }), - ], - ); + }, + ), + ]); }); test('camera position can set to front', () async { await picker.pickImage( - source: ImageSource.camera, - preferredCameraDevice: CameraDevice.front); + source: ImageSource.camera, + preferredCameraDevice: CameraDevice.front, + ); - expect( - log, - [ - isMethodCall('pickImage', arguments: { + expect(log, [ + isMethodCall( + 'pickImage', + arguments: { 'source': 0, 'maxWidth': null, 'maxHeight': null, 'imageQuality': null, 'cameraDevice': 1, 'requestFullMetadata': true, - }), - ], - ); + }, + ), + ]); }); }); @@ -239,101 +258,106 @@ void main() { returnValue = ['0', '1']; await picker.pickMultiImage(); - expect( - log, - [ - isMethodCall('pickMultiImage', arguments: { + expect(log, [ + isMethodCall( + 'pickMultiImage', + arguments: { 'maxWidth': null, 'maxHeight': null, 'imageQuality': null, 'requestFullMetadata': true, 'limit': null, - }), - ], - ); + }, + ), + ]); }); test('passes the width and height arguments correctly', () async { 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); + 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: { + expect(log, [ + isMethodCall( + 'pickMultiImage', + arguments: { 'maxWidth': null, 'maxHeight': null, 'imageQuality': null, 'requestFullMetadata': true, 'limit': null, - }), - isMethodCall('pickMultiImage', arguments: { + }, + ), + isMethodCall( + 'pickMultiImage', + arguments: { 'maxWidth': 10.0, 'maxHeight': null, 'imageQuality': null, 'requestFullMetadata': true, 'limit': null, - }), - isMethodCall('pickMultiImage', arguments: { + }, + ), + isMethodCall( + 'pickMultiImage', + arguments: { 'maxWidth': null, 'maxHeight': 10.0, 'imageQuality': null, 'requestFullMetadata': true, 'limit': null, - }), - isMethodCall('pickMultiImage', arguments: { + }, + ), + isMethodCall( + 'pickMultiImage', + arguments: { 'maxWidth': 10.0, 'maxHeight': 20.0, 'imageQuality': null, 'requestFullMetadata': true, 'limit': null, - }), - isMethodCall('pickMultiImage', arguments: { + }, + ), + isMethodCall( + 'pickMultiImage', + arguments: { 'maxWidth': 10.0, 'maxHeight': null, 'imageQuality': 70, 'requestFullMetadata': true, 'limit': null, - }), - isMethodCall('pickMultiImage', arguments: { + }, + ), + isMethodCall( + 'pickMultiImage', + arguments: { 'maxWidth': null, 'maxHeight': 10.0, 'imageQuality': 70, 'requestFullMetadata': true, 'limit': null, - }), - isMethodCall('pickMultiImage', arguments: { + }, + ), + isMethodCall( + 'pickMultiImage', + arguments: { 'maxWidth': 10.0, 'maxHeight': 20.0, 'imageQuality': 70, 'requestFullMetadata': true, 'limit': null, - }), - ], - ); + }, + ), + ]); }); test('does not accept a negative width or height argument', () { @@ -365,7 +389,9 @@ void main() { test('handles a null image path response gracefully', () async { TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger .setMockMethodCallHandler( - picker.channel, (MethodCall methodCall) => null); + picker.channel, + (MethodCall methodCall) => null, + ); expect(await picker.pickMultiImage(), isNull); expect(await picker.pickMultiImage(), isNull); @@ -377,21 +403,24 @@ void main() { await picker.pickVideo(source: ImageSource.camera); await picker.pickVideo(source: ImageSource.gallery); - expect( - log, - [ - isMethodCall('pickVideo', arguments: { + expect(log, [ + isMethodCall( + 'pickVideo', + arguments: { 'source': 0, 'cameraDevice': 0, 'maxDuration': null, - }), - isMethodCall('pickVideo', arguments: { + }, + ), + isMethodCall( + 'pickVideo', + arguments: { 'source': 1, 'cameraDevice': 0, 'maxDuration': null, - }), - ], - ); + }, + ), + ]); }); test('passes the duration argument correctly', () async { @@ -408,37 +437,48 @@ void main() { source: ImageSource.camera, maxDuration: const Duration(hours: 1), ); - expect( - log, - [ - isMethodCall('pickVideo', arguments: { + expect(log, [ + isMethodCall( + 'pickVideo', + arguments: { 'source': 0, 'maxDuration': null, 'cameraDevice': 0, - }), - isMethodCall('pickVideo', arguments: { + }, + ), + isMethodCall( + 'pickVideo', + arguments: { 'source': 0, 'maxDuration': 10, 'cameraDevice': 0, - }), - isMethodCall('pickVideo', arguments: { + }, + ), + isMethodCall( + 'pickVideo', + arguments: { 'source': 0, 'maxDuration': 60, 'cameraDevice': 0, - }), - isMethodCall('pickVideo', arguments: { + }, + ), + isMethodCall( + 'pickVideo', + arguments: { 'source': 0, 'maxDuration': 3600, 'cameraDevice': 0, - }), - ], - ); + }, + ), + ]); }); test('handles a null video path response gracefully', () async { TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger .setMockMethodCallHandler( - picker.channel, (MethodCall methodCall) => null); + picker.channel, + (MethodCall methodCall) => null, + ); expect(await picker.pickVideo(source: ImageSource.gallery), isNull); expect(await picker.pickVideo(source: ImageSource.camera), isNull); @@ -447,16 +487,16 @@ void main() { test('camera position defaults to back', () async { await picker.pickVideo(source: ImageSource.camera); - expect( - log, - [ - isMethodCall('pickVideo', arguments: { + expect(log, [ + isMethodCall( + 'pickVideo', + arguments: { 'source': 0, 'cameraDevice': 0, 'maxDuration': null, - }), - ], - ); + }, + ), + ]); }); test('camera position can set to front', () async { @@ -465,29 +505,27 @@ void main() { preferredCameraDevice: CameraDevice.front, ); - expect( - log, - [ - isMethodCall('pickVideo', arguments: { + expect(log, [ + isMethodCall( + 'pickVideo', + arguments: { 'source': 0, 'maxDuration': null, 'cameraDevice': 1, - }), - ], - ); + }, + ), + ]); }); }); group('#retrieveLostData', () { test('retrieveLostData get success response', () async { TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger - .setMockMethodCallHandler(picker.channel, - (MethodCall methodCall) async { - return { - 'type': 'image', - 'path': '/example/path', - }; - }); + .setMockMethodCallHandler(picker.channel, ( + MethodCall methodCall, + ) async { + return {'type': 'image', 'path': '/example/path'}; + }); final LostData response = await picker.retrieveLostData(); expect(response.type, RetrieveType.image); expect(response.file, isNotNull); @@ -496,14 +534,15 @@ void main() { test('retrieveLostData get error response', () async { TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger - .setMockMethodCallHandler(picker.channel, - (MethodCall methodCall) async { - return { - 'type': 'video', - 'errorCode': 'test_error_code', - 'errorMessage': 'test_error_message', - }; - }); + .setMockMethodCallHandler(picker.channel, ( + MethodCall methodCall, + ) async { + return { + 'type': 'video', + 'errorCode': 'test_error_code', + 'errorMessage': 'test_error_message', + }; + }); final LostData response = await picker.retrieveLostData(); expect(response.type, RetrieveType.video); expect(response.exception, isNotNull); @@ -513,24 +552,26 @@ void main() { test('retrieveLostData get null response', () async { TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger - .setMockMethodCallHandler(picker.channel, - (MethodCall methodCall) async { - return null; - }); + .setMockMethodCallHandler(picker.channel, ( + MethodCall methodCall, + ) async { + return null; + }); expect((await picker.retrieveLostData()).isEmpty, true); }); test('retrieveLostData get both path and error should throw', () async { TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger - .setMockMethodCallHandler(picker.channel, - (MethodCall methodCall) async { - return { - 'type': 'video', - 'errorCode': 'test_error_code', - 'errorMessage': 'test_error_message', - 'path': '/example/path', - }; - }); + .setMockMethodCallHandler(picker.channel, ( + MethodCall methodCall, + ) async { + return { + 'type': 'video', + 'errorCode': 'test_error_code', + 'errorMessage': 'test_error_message', + 'path': '/example/path', + }; + }); expect(picker.retrieveLostData(), throwsAssertionError); }); }); @@ -540,39 +581,36 @@ void main() { await picker.getImage(source: ImageSource.camera); await picker.getImage(source: ImageSource.gallery); - expect( - log, - [ - isMethodCall('pickImage', arguments: { + expect(log, [ + isMethodCall( + 'pickImage', + arguments: { 'source': 0, 'maxWidth': null, 'maxHeight': null, 'imageQuality': null, 'cameraDevice': 0, 'requestFullMetadata': true, - }), - isMethodCall('pickImage', arguments: { + }, + ), + isMethodCall( + 'pickImage', + arguments: { 'source': 1, 'maxWidth': null, 'maxHeight': null, 'imageQuality': null, 'cameraDevice': 0, 'requestFullMetadata': true, - }), - ], - ); + }, + ), + ]); }); 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); + await picker.getImage(source: ImageSource.camera, maxHeight: 10.0); await picker.getImage( source: ImageSource.camera, maxWidth: 10.0, @@ -595,67 +633,85 @@ void main() { imageQuality: 70, ); - expect( - log, - [ - isMethodCall('pickImage', arguments: { + expect(log, [ + isMethodCall( + 'pickImage', + arguments: { 'source': 0, 'maxWidth': null, 'maxHeight': null, 'imageQuality': null, 'cameraDevice': 0, 'requestFullMetadata': true, - }), - isMethodCall('pickImage', arguments: { + }, + ), + isMethodCall( + 'pickImage', + arguments: { 'source': 0, 'maxWidth': 10.0, 'maxHeight': null, 'imageQuality': null, 'cameraDevice': 0, 'requestFullMetadata': true, - }), - isMethodCall('pickImage', arguments: { + }, + ), + isMethodCall( + 'pickImage', + arguments: { 'source': 0, 'maxWidth': null, 'maxHeight': 10.0, 'imageQuality': null, 'cameraDevice': 0, 'requestFullMetadata': true, - }), - isMethodCall('pickImage', arguments: { + }, + ), + isMethodCall( + 'pickImage', + arguments: { 'source': 0, 'maxWidth': 10.0, 'maxHeight': 20.0, 'imageQuality': null, 'cameraDevice': 0, 'requestFullMetadata': true, - }), - isMethodCall('pickImage', arguments: { + }, + ), + isMethodCall( + 'pickImage', + arguments: { 'source': 0, 'maxWidth': 10.0, 'maxHeight': null, 'imageQuality': 70, 'cameraDevice': 0, 'requestFullMetadata': true, - }), - isMethodCall('pickImage', arguments: { + }, + ), + isMethodCall( + 'pickImage', + arguments: { 'source': 0, 'maxWidth': null, 'maxHeight': 10.0, 'imageQuality': 70, 'cameraDevice': 0, 'requestFullMetadata': true, - }), - isMethodCall('pickImage', arguments: { + }, + ), + isMethodCall( + 'pickImage', + arguments: { 'source': 0, 'maxWidth': 10.0, 'maxHeight': 20.0, 'imageQuality': 70, 'cameraDevice': 0, 'requestFullMetadata': true, - }), - ], - ); + }, + ), + ]); }); test('does not accept an invalid imageQuality argument', () { @@ -695,7 +751,9 @@ void main() { test('handles a null image path response gracefully', () async { TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger .setMockMethodCallHandler( - picker.channel, (MethodCall methodCall) => null); + picker.channel, + (MethodCall methodCall) => null, + ); expect(await picker.getImage(source: ImageSource.gallery), isNull); expect(await picker.getImage(source: ImageSource.camera), isNull); @@ -704,39 +762,40 @@ void main() { test('camera position defaults to back', () async { await picker.getImage(source: ImageSource.camera); - expect( - log, - [ - isMethodCall('pickImage', arguments: { + expect(log, [ + isMethodCall( + 'pickImage', + arguments: { 'source': 0, 'maxWidth': null, 'maxHeight': null, 'imageQuality': null, 'cameraDevice': 0, 'requestFullMetadata': true, - }), - ], - ); + }, + ), + ]); }); test('camera position can set to front', () async { await picker.getImage( - source: ImageSource.camera, - preferredCameraDevice: CameraDevice.front); + source: ImageSource.camera, + preferredCameraDevice: CameraDevice.front, + ); - expect( - log, - [ - isMethodCall('pickImage', arguments: { + expect(log, [ + isMethodCall( + 'pickImage', + arguments: { 'source': 0, 'maxWidth': null, 'maxHeight': null, 'imageQuality': null, 'cameraDevice': 1, 'requestFullMetadata': true, - }), - ], - ); + }, + ), + ]); }); }); @@ -745,109 +804,111 @@ void main() { returnValue = ['0', '1']; await picker.getMultiImage(); - expect( - log, - [ - isMethodCall('pickMultiImage', arguments: { + expect(log, [ + isMethodCall( + 'pickMultiImage', + arguments: { 'maxWidth': null, 'maxHeight': null, 'imageQuality': null, 'requestFullMetadata': true, 'limit': null, - }), - ], - ); + }, + ), + ]); }); test('passes the width and height arguments correctly', () async { 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); + 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, - [ - isMethodCall('pickMultiImage', arguments: { + expect(log, [ + isMethodCall( + 'pickMultiImage', + arguments: { 'maxWidth': null, 'maxHeight': null, 'imageQuality': null, 'requestFullMetadata': true, 'limit': null, - }), - isMethodCall('pickMultiImage', arguments: { + }, + ), + isMethodCall( + 'pickMultiImage', + arguments: { 'maxWidth': 10.0, 'maxHeight': null, 'imageQuality': null, 'requestFullMetadata': true, 'limit': null, - }), - isMethodCall('pickMultiImage', arguments: { + }, + ), + isMethodCall( + 'pickMultiImage', + arguments: { 'maxWidth': null, 'maxHeight': 10.0, 'imageQuality': null, 'requestFullMetadata': true, 'limit': null, - }), - isMethodCall('pickMultiImage', arguments: { + }, + ), + isMethodCall( + 'pickMultiImage', + arguments: { 'maxWidth': 10.0, 'maxHeight': 20.0, 'imageQuality': null, 'requestFullMetadata': true, 'limit': null, - }), - isMethodCall('pickMultiImage', arguments: { + }, + ), + isMethodCall( + 'pickMultiImage', + arguments: { 'maxWidth': 10.0, 'maxHeight': null, 'imageQuality': 70, 'requestFullMetadata': true, 'limit': null, - }), - isMethodCall('pickMultiImage', arguments: { + }, + ), + isMethodCall( + 'pickMultiImage', + arguments: { 'maxWidth': null, 'maxHeight': 10.0, 'imageQuality': 70, 'requestFullMetadata': true, 'limit': null, - }), - isMethodCall('pickMultiImage', arguments: { + }, + ), + isMethodCall( + 'pickMultiImage', + arguments: { 'maxWidth': 10.0, 'maxHeight': 20.0, 'imageQuality': 70, 'requestFullMetadata': true, 'limit': null, - }), - ], - ); + }, + ), + ]); }); test('does not accept a negative width or height argument', () { returnValue = ['0', '1']; - expect( - () => picker.getMultiImage(maxWidth: -1.0), - throwsArgumentError, - ); + expect(() => picker.getMultiImage(maxWidth: -1.0), throwsArgumentError); expect( () => picker.getMultiImage(maxHeight: -1.0), @@ -871,7 +932,9 @@ void main() { test('handles a null image path response gracefully', () async { TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger .setMockMethodCallHandler( - picker.channel, (MethodCall methodCall) => null); + picker.channel, + (MethodCall methodCall) => null, + ); expect(await picker.getMultiImage(), isNull); expect(await picker.getMultiImage(), isNull); @@ -882,103 +945,109 @@ void main() { test('calls the method correctly', () async { returnValue = ['0']; await picker.getMedia( - options: MediaOptions.createAndValidate(allowMultiple: true)); + options: MediaOptions.createAndValidate(allowMultiple: true), + ); - expect( - log, - [ - isMethodCall('pickMedia', arguments: { + expect(log, [ + isMethodCall( + 'pickMedia', + arguments: { 'maxImageWidth': null, 'maxImageHeight': null, 'imageQuality': null, 'allowMultiple': true, 'limit': null, - }), - ], - ); + }, + ), + ]); }); test('passes the selection options correctly', () async { // Default options returnValue = ['0']; await picker.getMedia( - options: MediaOptions.createAndValidate(allowMultiple: true)); + options: MediaOptions.createAndValidate(allowMultiple: true), + ); // Various image options returnValue = ['0']; await picker.getMedia( options: MediaOptions.createAndValidate( allowMultiple: true, - imageOptions: ImageOptions.createAndValidate( - maxWidth: 10.0, - ), + imageOptions: ImageOptions.createAndValidate(maxWidth: 10.0), ), ); await picker.getMedia( options: MediaOptions.createAndValidate( allowMultiple: true, - imageOptions: ImageOptions.createAndValidate( - maxHeight: 10.0, - ), + imageOptions: ImageOptions.createAndValidate(maxHeight: 10.0), ), ); await picker.getMedia( options: MediaOptions.createAndValidate( allowMultiple: true, - imageOptions: ImageOptions.createAndValidate( - imageQuality: 70, - ), + imageOptions: ImageOptions.createAndValidate(imageQuality: 70), ), ); await picker.getMedia( options: MediaOptions.createAndValidate( allowMultiple: true, - imageOptions: ImageOptions.createAndValidate( - imageQuality: 70, - ), + imageOptions: ImageOptions.createAndValidate(imageQuality: 70), limit: 5, ), ); - expect( - log, - [ - isMethodCall('pickMedia', arguments: { + expect(log, [ + isMethodCall( + 'pickMedia', + arguments: { 'maxImageWidth': null, 'maxImageHeight': null, 'imageQuality': null, 'allowMultiple': true, 'limit': null, - }), - isMethodCall('pickMedia', arguments: { + }, + ), + isMethodCall( + 'pickMedia', + arguments: { 'maxImageWidth': 10.0, 'maxImageHeight': null, 'imageQuality': null, 'allowMultiple': true, 'limit': null, - }), - isMethodCall('pickMedia', arguments: { + }, + ), + isMethodCall( + 'pickMedia', + arguments: { 'maxImageWidth': null, 'maxImageHeight': 10.0, 'imageQuality': null, 'allowMultiple': true, 'limit': null, - }), - isMethodCall('pickMedia', arguments: { + }, + ), + isMethodCall( + 'pickMedia', + arguments: { 'maxImageWidth': null, 'maxImageHeight': null, 'imageQuality': 70, 'allowMultiple': true, 'limit': null, - }), - isMethodCall('pickMedia', arguments: { + }, + ), + isMethodCall( + 'pickMedia', + arguments: { 'maxImageWidth': null, 'maxImageHeight': null, 'imageQuality': 70, 'allowMultiple': true, 'limit': 5, - }), - ], - ); + }, + ), + ]); }); test('does not accept a negative width or height argument', () { @@ -987,9 +1056,7 @@ void main() { () => picker.getMedia( options: MediaOptions.createAndValidate( allowMultiple: true, - imageOptions: ImageOptions.createAndValidate( - maxWidth: -1.0, - ), + imageOptions: ImageOptions.createAndValidate(maxWidth: -1.0), ), ), throwsArgumentError, @@ -999,9 +1066,7 @@ void main() { () => picker.getMedia( options: MediaOptions.createAndValidate( allowMultiple: true, - imageOptions: ImageOptions.createAndValidate( - maxHeight: -1.0, - ), + imageOptions: ImageOptions.createAndValidate(maxHeight: -1.0), ), ), throwsArgumentError, @@ -1014,9 +1079,7 @@ void main() { () => picker.getMedia( options: MediaOptions.createAndValidate( allowMultiple: true, - imageOptions: ImageOptions.createAndValidate( - imageQuality: -1, - ), + imageOptions: ImageOptions.createAndValidate(imageQuality: -1), ), ), throwsArgumentError, @@ -1026,9 +1089,7 @@ void main() { () => picker.getMedia( options: MediaOptions.createAndValidate( allowMultiple: true, - imageOptions: ImageOptions.createAndValidate( - imageQuality: 101, - ), + imageOptions: ImageOptions.createAndValidate(imageQuality: 101), ), ), throwsArgumentError, @@ -1039,8 +1100,10 @@ void main() { returnValue = ['0', '1']; expect( () => picker.getMedia( - options: - MediaOptions.createAndValidate(allowMultiple: true, limit: -1), + options: MediaOptions.createAndValidate( + allowMultiple: true, + limit: -1, + ), ), throwsArgumentError, ); @@ -1059,8 +1122,10 @@ void main() { test('does not accept a not null limit when allowMultiple is false', () { expect( () => picker.getMedia( - options: - MediaOptions.createAndValidate(allowMultiple: false, limit: 5), + options: MediaOptions.createAndValidate( + allowMultiple: false, + limit: 5, + ), ), throwsArgumentError, ); @@ -1069,11 +1134,15 @@ void main() { test('handles a null path response gracefully', () async { TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger .setMockMethodCallHandler( - picker.channel, (MethodCall methodCall) => null); + picker.channel, + (MethodCall methodCall) => null, + ); expect( - await picker.getMedia( - options: MediaOptions.createAndValidate(allowMultiple: true)), - []); + await picker.getMedia( + options: MediaOptions.createAndValidate(allowMultiple: true), + ), + [], + ); }); }); @@ -1082,21 +1151,24 @@ void main() { await picker.getVideo(source: ImageSource.camera); await picker.getVideo(source: ImageSource.gallery); - expect( - log, - [ - isMethodCall('pickVideo', arguments: { + expect(log, [ + isMethodCall( + 'pickVideo', + arguments: { 'source': 0, 'cameraDevice': 0, 'maxDuration': null, - }), - isMethodCall('pickVideo', arguments: { + }, + ), + isMethodCall( + 'pickVideo', + arguments: { 'source': 1, 'cameraDevice': 0, 'maxDuration': null, - }), - ], - ); + }, + ), + ]); }); test('passes the duration argument correctly', () async { @@ -1113,37 +1185,48 @@ void main() { source: ImageSource.camera, maxDuration: const Duration(hours: 1), ); - expect( - log, - [ - isMethodCall('pickVideo', arguments: { + expect(log, [ + isMethodCall( + 'pickVideo', + arguments: { 'source': 0, 'maxDuration': null, 'cameraDevice': 0, - }), - isMethodCall('pickVideo', arguments: { + }, + ), + isMethodCall( + 'pickVideo', + arguments: { 'source': 0, 'maxDuration': 10, 'cameraDevice': 0, - }), - isMethodCall('pickVideo', arguments: { + }, + ), + isMethodCall( + 'pickVideo', + arguments: { 'source': 0, 'maxDuration': 60, 'cameraDevice': 0, - }), - isMethodCall('pickVideo', arguments: { + }, + ), + isMethodCall( + 'pickVideo', + arguments: { 'source': 0, 'maxDuration': 3600, 'cameraDevice': 0, - }), - ], - ); + }, + ), + ]); }); test('handles a null video path response gracefully', () async { TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger .setMockMethodCallHandler( - picker.channel, (MethodCall methodCall) => null); + picker.channel, + (MethodCall methodCall) => null, + ); expect(await picker.getVideo(source: ImageSource.gallery), isNull); expect(await picker.getVideo(source: ImageSource.camera), isNull); @@ -1152,16 +1235,16 @@ void main() { test('camera position defaults to back', () async { await picker.getVideo(source: ImageSource.camera); - expect( - log, - [ - isMethodCall('pickVideo', arguments: { + expect(log, [ + isMethodCall( + 'pickVideo', + arguments: { 'source': 0, 'cameraDevice': 0, 'maxDuration': null, - }), - ], - ); + }, + ), + ]); }); test('camera position can set to front', () async { @@ -1170,29 +1253,27 @@ void main() { preferredCameraDevice: CameraDevice.front, ); - expect( - log, - [ - isMethodCall('pickVideo', arguments: { + expect(log, [ + isMethodCall( + 'pickVideo', + arguments: { 'source': 0, 'maxDuration': null, 'cameraDevice': 1, - }), - ], - ); + }, + ), + ]); }); }); group('#getLostData', () { test('getLostData get success response', () async { TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger - .setMockMethodCallHandler(picker.channel, - (MethodCall methodCall) async { - return { - 'type': 'image', - 'path': '/example/path', - }; - }); + .setMockMethodCallHandler(picker.channel, ( + MethodCall methodCall, + ) async { + return {'type': 'image', 'path': '/example/path'}; + }); final LostDataResponse response = await picker.getLostData(); expect(response.type, RetrieveType.image); expect(response.file, isNotNull); @@ -1201,14 +1282,15 @@ void main() { test('getLostData should successfully retrieve multiple files', () async { TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger - .setMockMethodCallHandler(picker.channel, - (MethodCall methodCall) async { - return { - 'type': 'image', - 'path': '/example/path1', - 'pathList': ['/example/path0', '/example/path1'], - }; - }); + .setMockMethodCallHandler(picker.channel, ( + MethodCall methodCall, + ) async { + return { + 'type': 'image', + 'path': '/example/path1', + 'pathList': ['/example/path0', '/example/path1'], + }; + }); final LostDataResponse response = await picker.getLostData(); expect(response.type, RetrieveType.image); expect(response.file, isNotNull); @@ -1219,14 +1301,15 @@ void main() { test('getLostData get error response', () async { TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger - .setMockMethodCallHandler(picker.channel, - (MethodCall methodCall) async { - return { - 'type': 'video', - 'errorCode': 'test_error_code', - 'errorMessage': 'test_error_message', - }; - }); + .setMockMethodCallHandler(picker.channel, ( + MethodCall methodCall, + ) async { + return { + 'type': 'video', + 'errorCode': 'test_error_code', + 'errorMessage': 'test_error_message', + }; + }); final LostDataResponse response = await picker.getLostData(); expect(response.type, RetrieveType.video); expect(response.exception, isNotNull); @@ -1236,24 +1319,26 @@ void main() { test('getLostData get null response', () async { TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger - .setMockMethodCallHandler(picker.channel, - (MethodCall methodCall) async { - return null; - }); + .setMockMethodCallHandler(picker.channel, ( + MethodCall methodCall, + ) async { + return null; + }); expect((await picker.getLostData()).isEmpty, true); }); test('getLostData get both path and error should throw', () async { TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger - .setMockMethodCallHandler(picker.channel, - (MethodCall methodCall) async { - return { - 'type': 'video', - 'errorCode': 'test_error_code', - 'errorMessage': 'test_error_message', - 'path': '/example/path', - }; - }); + .setMockMethodCallHandler(picker.channel, ( + MethodCall methodCall, + ) async { + return { + 'type': 'video', + 'errorCode': 'test_error_code', + 'errorMessage': 'test_error_message', + 'path': '/example/path', + }; + }); expect(picker.getLostData(), throwsAssertionError); }); }); @@ -1263,27 +1348,30 @@ void main() { await picker.getImageFromSource(source: ImageSource.camera); await picker.getImageFromSource(source: ImageSource.gallery); - expect( - log, - [ - isMethodCall('pickImage', arguments: { + expect(log, [ + isMethodCall( + 'pickImage', + arguments: { 'source': 0, 'maxWidth': null, 'maxHeight': null, 'imageQuality': null, 'cameraDevice': 0, 'requestFullMetadata': true, - }), - isMethodCall('pickImage', arguments: { + }, + ), + isMethodCall( + 'pickImage', + arguments: { 'source': 1, 'maxWidth': null, 'maxHeight': null, 'imageQuality': null, 'cameraDevice': 0, 'requestFullMetadata': true, - }), - ], - ); + }, + ), + ]); }); test('passes the width and height arguments correctly', () async { @@ -1298,24 +1386,15 @@ void main() { ); await picker.getImageFromSource( source: ImageSource.camera, - options: const ImagePickerOptions( - maxWidth: 10.0, - maxHeight: 20.0, - ), + options: const ImagePickerOptions(maxWidth: 10.0, maxHeight: 20.0), ); await picker.getImageFromSource( source: ImageSource.camera, - options: const ImagePickerOptions( - maxWidth: 10.0, - imageQuality: 70, - ), + options: const ImagePickerOptions(maxWidth: 10.0, imageQuality: 70), ); await picker.getImageFromSource( source: ImageSource.camera, - options: const ImagePickerOptions( - maxHeight: 10.0, - imageQuality: 70, - ), + options: const ImagePickerOptions(maxHeight: 10.0, imageQuality: 70), ); await picker.getImageFromSource( source: ImageSource.camera, @@ -1326,67 +1405,85 @@ void main() { ), ); - expect( - log, - [ - isMethodCall('pickImage', arguments: { + expect(log, [ + isMethodCall( + 'pickImage', + arguments: { 'source': 0, 'maxWidth': null, 'maxHeight': null, 'imageQuality': null, 'cameraDevice': 0, 'requestFullMetadata': true, - }), - isMethodCall('pickImage', arguments: { + }, + ), + isMethodCall( + 'pickImage', + arguments: { 'source': 0, 'maxWidth': 10.0, 'maxHeight': null, 'imageQuality': null, 'cameraDevice': 0, 'requestFullMetadata': true, - }), - isMethodCall('pickImage', arguments: { + }, + ), + isMethodCall( + 'pickImage', + arguments: { 'source': 0, 'maxWidth': null, 'maxHeight': 10.0, 'imageQuality': null, 'cameraDevice': 0, 'requestFullMetadata': true, - }), - isMethodCall('pickImage', arguments: { + }, + ), + isMethodCall( + 'pickImage', + arguments: { 'source': 0, 'maxWidth': 10.0, 'maxHeight': 20.0, 'imageQuality': null, 'cameraDevice': 0, 'requestFullMetadata': true, - }), - isMethodCall('pickImage', arguments: { + }, + ), + isMethodCall( + 'pickImage', + arguments: { 'source': 0, 'maxWidth': 10.0, 'maxHeight': null, 'imageQuality': 70, 'cameraDevice': 0, 'requestFullMetadata': true, - }), - isMethodCall('pickImage', arguments: { + }, + ), + isMethodCall( + 'pickImage', + arguments: { 'source': 0, 'maxWidth': null, 'maxHeight': 10.0, 'imageQuality': 70, 'cameraDevice': 0, 'requestFullMetadata': true, - }), - isMethodCall('pickImage', arguments: { + }, + ), + isMethodCall( + 'pickImage', + arguments: { 'source': 0, 'maxWidth': 10.0, 'maxHeight': 20.0, 'imageQuality': 70, 'cameraDevice': 0, 'requestFullMetadata': true, - }), - ], - ); + }, + ), + ]); }); test('does not accept an invalid imageQuality argument', () { @@ -1444,30 +1541,36 @@ void main() { test('handles a null image path response gracefully', () async { TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger .setMockMethodCallHandler( - picker.channel, (MethodCall methodCall) => null); + picker.channel, + (MethodCall methodCall) => null, + ); - expect(await picker.getImageFromSource(source: ImageSource.gallery), - isNull); - expect(await picker.getImageFromSource(source: ImageSource.camera), - isNull); + expect( + await picker.getImageFromSource(source: ImageSource.gallery), + isNull, + ); + expect( + await picker.getImageFromSource(source: ImageSource.camera), + isNull, + ); }); test('camera position defaults to back', () async { await picker.getImageFromSource(source: ImageSource.camera); - expect( - log, - [ - isMethodCall('pickImage', arguments: { + expect(log, [ + isMethodCall( + 'pickImage', + arguments: { 'source': 0, 'maxWidth': null, 'maxHeight': null, 'imageQuality': null, 'cameraDevice': 0, 'requestFullMetadata': true, - }), - ], - ); + }, + ), + ]); }); test('camera position can set to front', () async { @@ -1478,19 +1581,19 @@ void main() { ), ); - expect( - log, - [ - isMethodCall('pickImage', arguments: { + expect(log, [ + isMethodCall( + 'pickImage', + arguments: { 'source': 0, 'maxWidth': null, 'maxHeight': null, 'imageQuality': null, 'cameraDevice': 1, 'requestFullMetadata': true, - }), - ], - ); + }, + ), + ]); }); test('passes the full metadata argument correctly', () async { @@ -1499,19 +1602,19 @@ void main() { options: const ImagePickerOptions(requestFullMetadata: false), ); - expect( - log, - [ - isMethodCall('pickImage', arguments: { + expect(log, [ + isMethodCall( + 'pickImage', + arguments: { 'source': 0, 'maxWidth': null, 'maxHeight': null, 'imageQuality': null, 'cameraDevice': 0, 'requestFullMetadata': false, - }), - ], - ); + }, + ), + ]); }); }); @@ -1520,140 +1623,154 @@ void main() { returnValue = ['0', '1']; await picker.getMultiImageWithOptions(); - expect( - log, - [ - isMethodCall('pickMultiImage', arguments: { + expect(log, [ + isMethodCall( + 'pickMultiImage', + arguments: { 'maxWidth': null, 'maxHeight': null, 'imageQuality': null, 'requestFullMetadata': true, 'limit': null, - }), - ], - ); + }, + ), + ]); }); - test('passes the width, height and imageQuality arguments correctly', - () async { - 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, + test( + 'passes the width, height and imageQuality arguments correctly', + () async { + 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( - maxWidth: 10.0, - imageQuality: 70, + ); + await picker.getMultiImageWithOptions( + options: const MultiImagePickerOptions( + imageOptions: ImageOptions(maxHeight: 10.0), ), - ), - ); - 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), ), - ), - ); - await picker.getMultiImageWithOptions( - options: const MultiImagePickerOptions( - imageOptions: ImageOptions( - maxWidth: 10.0, - maxHeight: 20.0, - imageQuality: 70, + ); + await picker.getMultiImageWithOptions( + options: const MultiImagePickerOptions( + imageOptions: ImageOptions(maxWidth: 10.0, imageQuality: 70), ), - ), - ); - await picker.getMultiImageWithOptions( - options: const MultiImagePickerOptions( - imageOptions: ImageOptions( - maxWidth: 10.0, - maxHeight: 20.0, - imageQuality: 70, + ); + await picker.getMultiImageWithOptions( + options: const MultiImagePickerOptions( + imageOptions: ImageOptions(maxHeight: 10.0, imageQuality: 70), ), - limit: 5, - ), - ); - - expect( - log, - [ - isMethodCall('pickMultiImage', arguments: { - 'maxWidth': null, - 'maxHeight': null, - 'imageQuality': null, - 'requestFullMetadata': true, - 'limit': null, - }), - isMethodCall('pickMultiImage', arguments: { - 'maxWidth': 10.0, - 'maxHeight': null, - 'imageQuality': null, - 'requestFullMetadata': true, - 'limit': null, - }), - isMethodCall('pickMultiImage', arguments: { - 'maxWidth': null, - 'maxHeight': 10.0, - 'imageQuality': null, - 'requestFullMetadata': true, - 'limit': null, - }), - isMethodCall('pickMultiImage', arguments: { - 'maxWidth': 10.0, - 'maxHeight': 20.0, - 'imageQuality': null, - 'requestFullMetadata': true, - 'limit': null, - }), - isMethodCall('pickMultiImage', arguments: { - 'maxWidth': 10.0, - 'maxHeight': null, - 'imageQuality': 70, - 'requestFullMetadata': true, - 'limit': null, - }), - isMethodCall('pickMultiImage', arguments: { - 'maxWidth': null, - 'maxHeight': 10.0, - 'imageQuality': 70, - 'requestFullMetadata': true, - 'limit': null, - }), - isMethodCall('pickMultiImage', arguments: { - 'maxWidth': 10.0, - 'maxHeight': 20.0, - 'imageQuality': 70, - 'requestFullMetadata': true, - 'limit': null, - }), - isMethodCall('pickMultiImage', arguments: { - 'maxWidth': 10.0, - 'maxHeight': 20.0, - 'imageQuality': 70, - 'requestFullMetadata': true, - 'limit': 5, - }), - ], - ); - }); + ); + await picker.getMultiImageWithOptions( + options: const MultiImagePickerOptions( + imageOptions: ImageOptions( + maxWidth: 10.0, + maxHeight: 20.0, + imageQuality: 70, + ), + ), + ); + await picker.getMultiImageWithOptions( + options: const MultiImagePickerOptions( + imageOptions: ImageOptions( + maxWidth: 10.0, + maxHeight: 20.0, + imageQuality: 70, + ), + limit: 5, + ), + ); + + expect(log, [ + isMethodCall( + 'pickMultiImage', + arguments: { + 'maxWidth': null, + 'maxHeight': null, + 'imageQuality': null, + 'requestFullMetadata': true, + 'limit': null, + }, + ), + isMethodCall( + 'pickMultiImage', + arguments: { + 'maxWidth': 10.0, + 'maxHeight': null, + 'imageQuality': null, + 'requestFullMetadata': true, + 'limit': null, + }, + ), + isMethodCall( + 'pickMultiImage', + arguments: { + 'maxWidth': null, + 'maxHeight': 10.0, + 'imageQuality': null, + 'requestFullMetadata': true, + 'limit': null, + }, + ), + isMethodCall( + 'pickMultiImage', + arguments: { + 'maxWidth': 10.0, + 'maxHeight': 20.0, + 'imageQuality': null, + 'requestFullMetadata': true, + 'limit': null, + }, + ), + isMethodCall( + 'pickMultiImage', + arguments: { + 'maxWidth': 10.0, + 'maxHeight': null, + 'imageQuality': 70, + 'requestFullMetadata': true, + 'limit': null, + }, + ), + isMethodCall( + 'pickMultiImage', + arguments: { + 'maxWidth': null, + 'maxHeight': 10.0, + 'imageQuality': 70, + 'requestFullMetadata': true, + 'limit': null, + }, + ), + isMethodCall( + 'pickMultiImage', + arguments: { + 'maxWidth': 10.0, + 'maxHeight': 20.0, + 'imageQuality': 70, + 'requestFullMetadata': true, + 'limit': null, + }, + ), + isMethodCall( + 'pickMultiImage', + arguments: { + 'maxWidth': 10.0, + 'maxHeight': 20.0, + 'imageQuality': 70, + 'requestFullMetadata': true, + 'limit': 5, + }, + ), + ]); + }, + ); test('does not accept a negative width or height argument', () { returnValue = ['0', '1']; @@ -1701,27 +1818,21 @@ void main() { returnValue = ['0', '1']; expect( () => picker.getMultiImageWithOptions( - options: MultiImagePickerOptions.createAndValidate( - limit: -1, - ), + options: MultiImagePickerOptions.createAndValidate(limit: -1), ), throwsArgumentError, ); expect( () => picker.getMultiImageWithOptions( - options: MultiImagePickerOptions.createAndValidate( - limit: 0, - ), + options: MultiImagePickerOptions.createAndValidate(limit: 0), ), throwsArgumentError, ); expect( () => picker.getMultiImageWithOptions( - options: MultiImagePickerOptions.createAndValidate( - limit: 1, - ), + options: MultiImagePickerOptions.createAndValidate(limit: 1), ), throwsArgumentError, ); @@ -1730,7 +1841,9 @@ void main() { test('handles a null image path response gracefully', () async { TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger .setMockMethodCallHandler( - picker.channel, (MethodCall methodCall) => null); + picker.channel, + (MethodCall methodCall) => null, + ); expect(await picker.getMultiImage(), isNull); expect(await picker.getMultiImage(), isNull); @@ -1740,18 +1853,18 @@ void main() { returnValue = ['0', '1']; await picker.getMultiImageWithOptions(); - expect( - log, - [ - isMethodCall('pickMultiImage', arguments: { + expect(log, [ + isMethodCall( + 'pickMultiImage', + arguments: { 'maxWidth': null, 'maxHeight': null, 'imageQuality': null, 'requestFullMetadata': true, 'limit': null, - }), - ], - ); + }, + ), + ]); }); test('passes the request full metadata argument correctly', () async { @@ -1762,18 +1875,18 @@ void main() { ), ); - expect( - log, - [ - isMethodCall('pickMultiImage', arguments: { + expect(log, [ + isMethodCall( + 'pickMultiImage', + arguments: { 'maxWidth': null, 'maxHeight': null, 'imageQuality': null, 'requestFullMetadata': false, 'limit': null, - }), - ], - ); + }, + ), + ]); }); }); }); diff --git a/packages/image_picker/image_picker_platform_interface/test/picked_file_html_test.dart b/packages/image_picker/image_picker_platform_interface/test/picked_file_html_test.dart index cc2191444ae..c05e90c11c9 100644 --- a/packages/image_picker/image_picker_platform_interface/test/picked_file_html_test.dart +++ b/packages/image_picker/image_picker_platform_interface/test/picked_file_html_test.dart @@ -15,8 +15,10 @@ import 'package:web/web.dart' as web; const String expectedStringContents = 'Hello, world!'; final Uint8List bytes = utf8.encode(expectedStringContents); -final web.File textFile = - web.File([bytes.toJS].toJS, 'hello.txt'); +final web.File textFile = web.File( + [bytes.toJS].toJS, + 'hello.txt', +); final String textFileUrl = web.URL.createObjectURL(textFile); void main() { @@ -36,7 +38,9 @@ void main() { test('Stream can be sliced', () async { expect( - await pickedFile.openRead(2, 5).first, equals(bytes.sublist(2, 5))); + await pickedFile.openRead(2, 5).first, + equals(bytes.sublist(2, 5)), + ); }); }); } diff --git a/packages/image_picker/image_picker_platform_interface/test/picked_file_io_test.dart b/packages/image_picker/image_picker_platform_interface/test/picked_file_io_test.dart index 14b6a8b4139..85c16f6457a 100644 --- a/packages/image_picker/image_picker_platform_interface/test/picked_file_io_test.dart +++ b/packages/image_picker/image_picker_platform_interface/test/picked_file_io_test.dart @@ -37,7 +37,9 @@ void main() { test('Stream can be sliced', () async { expect( - await pickedFile.openRead(2, 5).first, equals(bytes.sublist(2, 5))); + await pickedFile.openRead(2, 5).first, + equals(bytes.sublist(2, 5)), + ); }); }); } diff --git a/packages/image_picker/image_picker_windows/CHANGELOG.md b/packages/image_picker/image_picker_windows/CHANGELOG.md index 80b3c931b49..e738b72f25c 100644 --- a/packages/image_picker/image_picker_windows/CHANGELOG.md +++ b/packages/image_picker/image_picker_windows/CHANGELOG.md @@ -1,3 +1,7 @@ +## NEXT + +* Updates minimum supported SDK version to Flutter 3.29/Dart 3.7. + ## 0.2.2 * Adds support for `getMultiVideoWithOptions`. diff --git a/packages/image_picker/image_picker_windows/example/lib/main.dart b/packages/image_picker/image_picker_windows/example/lib/main.dart index b62d3913397..ff9ebda808c 100644 --- a/packages/image_picker/image_picker_windows/example/lib/main.dart +++ b/packages/image_picker/image_picker_windows/example/lib/main.dart @@ -60,8 +60,9 @@ class _MyHomePageState extends State { Future _playVideo(XFile? file) async { if (file != null && mounted) { await _disposeVideoController(); - final VideoPlayerController controller = - VideoPlayerController.file(File(file.path)); + final VideoPlayerController controller = VideoPlayerController.file( + File(file.path), + ); _controller = controller; await controller.setVolume(1.0); await controller.initialize(); @@ -87,7 +88,9 @@ class _MyHomePageState extends State { files = await _picker.getMultiVideoWithOptions(); } else { final XFile? file = await _picker.getVideo( - source: source, maxDuration: const Duration(seconds: 10)); + source: source, + maxDuration: const Duration(seconds: 10), + ); files = [if (file != null) file]; } if (files.isNotEmpty && context.mounted) { @@ -96,26 +99,30 @@ class _MyHomePageState extends State { await _playVideo(files.first); } } else if (allowMultiple) { - await _displayPickImageDialog(context, - (double? maxWidth, double? maxHeight, int? quality) async { + await _displayPickImageDialog(context, ( + double? maxWidth, + double? maxHeight, + int? quality, + ) async { try { final ImageOptions imageOptions = ImageOptions( maxWidth: maxWidth, maxHeight: maxHeight, imageQuality: quality, ); - final List pickedFileList = isMedia - ? await _picker.getMedia( - options: MediaOptions( - allowMultiple: allowMultiple, - imageOptions: imageOptions, - ), - ) - : await _picker.getMultiImageWithOptions( - options: MultiImagePickerOptions( - imageOptions: imageOptions, - ), - ); + final List pickedFileList = + isMedia + ? await _picker.getMedia( + options: MediaOptions( + allowMultiple: allowMultiple, + imageOptions: imageOptions, + ), + ) + : await _picker.getMultiImageWithOptions( + options: MultiImagePickerOptions( + imageOptions: imageOptions, + ), + ); if (pickedFileList.isNotEmpty && context.mounted) { _showPickedSnackBar(context, pickedFileList); } @@ -129,19 +136,25 @@ class _MyHomePageState extends State { } }); } else if (isMedia) { - await _displayPickImageDialog(context, - (double? maxWidth, double? maxHeight, int? quality) async { + await _displayPickImageDialog(context, ( + double? maxWidth, + double? maxHeight, + int? quality, + ) async { try { final List pickedFileList = []; - final XFile? media = _firstOrNull(await _picker.getMedia( - options: MediaOptions( + final XFile? media = _firstOrNull( + await _picker.getMedia( + options: MediaOptions( allowMultiple: allowMultiple, imageOptions: ImageOptions( maxWidth: maxWidth, maxHeight: maxHeight, imageQuality: quality, - )), - )); + ), + ), + ), + ); if (media != null) { pickedFileList.add(media); @@ -154,8 +167,11 @@ class _MyHomePageState extends State { } }); } else { - await _displayPickImageDialog(context, - (double? maxWidth, double? maxHeight, int? quality) async { + await _displayPickImageDialog(context, ( + double? maxWidth, + double? maxHeight, + int? quality, + ) async { try { final XFile? pickedFile = await _picker.getImageFromSource( source: source, @@ -236,21 +252,27 @@ class _MyHomePageState extends State { return Column( mainAxisSize: MainAxisSize.min, children: [ - Text(image.name, - key: const Key('image_picker_example_picked_image_name')), + Text( + image.name, + key: const Key('image_picker_example_picked_image_name'), + ), Semantics( label: 'image_picker_example_picked_image', - child: mime == null || mime.startsWith('image/') - ? Image.file( - File(_mediaFileList![index].path), - errorBuilder: (BuildContext context, Object error, - StackTrace? stackTrace) { - return const Center( - child: - Text('This image type is not supported')); - }, - ) - : _buildInlineVideoPlayer(index), + child: + mime == null || mime.startsWith('image/') + ? Image.file( + File(_mediaFileList![index].path), + errorBuilder: ( + BuildContext context, + Object error, + StackTrace? stackTrace, + ) { + return const Center( + child: Text('This image type is not supported'), + ); + }, + ) + : _buildInlineVideoPlayer(index), ), ], ); @@ -272,8 +294,9 @@ class _MyHomePageState extends State { } Widget _buildInlineVideoPlayer(int index) { - final VideoPlayerController controller = - VideoPlayerController.file(File(_mediaFileList![index].path)); + final VideoPlayerController controller = VideoPlayerController.file( + File(_mediaFileList![index].path), + ); controller.setVolume(1.0); controller.initialize(); controller.setLooping(true); @@ -292,13 +315,8 @@ class _MyHomePageState extends State { @override Widget build(BuildContext context) { return Scaffold( - appBar: AppBar( - title: Text(widget.title!), - ), - body: Align( - alignment: Alignment.topCenter, - child: _handlePreview(), - ), + appBar: AppBar(title: Text(widget.title!)), + body: Align(alignment: Alignment.topCenter, child: _handlePreview()), floatingActionButton: Column( mainAxisAlignment: MainAxisAlignment.end, children: [ @@ -402,8 +420,11 @@ class _MyHomePageState extends State { backgroundColor: Colors.red, onPressed: () { _isVideo = true; - _onImageButtonPressed(ImageSource.gallery, - context: context, allowMultiple: true); + _onImageButtonPressed( + ImageSource.gallery, + context: context, + allowMultiple: true, + ); }, heroTag: 'multiVideo', tooltip: 'Pick multiple videos', @@ -441,73 +462,87 @@ class _MyHomePageState extends State { } Future _displayPickImageDialog( - BuildContext context, OnPickImageCallback onPick) async { + BuildContext context, + OnPickImageCallback onPick, + ) async { return showDialog( - context: context, - builder: (BuildContext context) { - return AlertDialog( - title: const Text('Add optional parameters'), - content: Column( - children: [ - TextField( - controller: maxWidthController, - keyboardType: - const TextInputType.numberWithOptions(decimal: true), - decoration: const InputDecoration( - hintText: 'Enter maxWidth if desired'), + context: context, + builder: (BuildContext context) { + return AlertDialog( + title: const Text('Add optional parameters'), + content: Column( + children: [ + TextField( + controller: maxWidthController, + keyboardType: const TextInputType.numberWithOptions( + decimal: true, ), - TextField( - controller: maxHeightController, - keyboardType: - const TextInputType.numberWithOptions(decimal: true), - decoration: const InputDecoration( - hintText: 'Enter maxHeight if desired'), + decoration: const InputDecoration( + hintText: 'Enter maxWidth if desired', ), - TextField( - controller: qualityController, - keyboardType: TextInputType.number, - decoration: const InputDecoration( - hintText: 'Enter quality if desired'), + ), + TextField( + controller: maxHeightController, + keyboardType: const TextInputType.numberWithOptions( + decimal: true, + ), + decoration: const InputDecoration( + hintText: 'Enter maxHeight if desired', ), - ], - ), - actions: [ - TextButton( - child: const Text('CANCEL'), - onPressed: () { - Navigator.of(context).pop(); - }, ), - TextButton( - child: const Text('PICK'), - onPressed: () { - final double? width = maxWidthController.text.isNotEmpty + TextField( + controller: qualityController, + keyboardType: TextInputType.number, + decoration: const InputDecoration( + hintText: 'Enter quality if desired', + ), + ), + ], + ), + actions: [ + TextButton( + child: const Text('CANCEL'), + onPressed: () { + Navigator.of(context).pop(); + }, + ), + TextButton( + child: const Text('PICK'), + onPressed: () { + final double? width = + maxWidthController.text.isNotEmpty ? double.parse(maxWidthController.text) : null; - final double? height = maxHeightController.text.isNotEmpty + final double? height = + maxHeightController.text.isNotEmpty ? double.parse(maxHeightController.text) : null; - final int? quality = qualityController.text.isNotEmpty + final int? quality = + qualityController.text.isNotEmpty ? int.parse(qualityController.text) : null; - onPick(width, height, quality); - Navigator.of(context).pop(); - }), - ], - ); - }); + onPick(width, height, quality); + Navigator.of(context).pop(); + }, + ), + ], + ); + }, + ); } void _showPickedSnackBar(BuildContext context, List files) { - ScaffoldMessenger.of(context).showSnackBar(SnackBar( - content: Text('Picked: ${files.map((XFile it) => it.name).join(',')}'), - duration: const Duration(seconds: 2), - )); + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text('Picked: ${files.map((XFile it) => it.name).join(',')}'), + duration: const Duration(seconds: 2), + ), + ); } } -typedef OnPickImageCallback = void Function( - double? maxWidth, double? maxHeight, int? quality); +typedef OnPickImageCallback = + void Function(double? maxWidth, double? maxHeight, int? quality); class AspectRatioVideo extends StatefulWidget { const AspectRatioVideo(this.controller, {super.key}); diff --git a/packages/image_picker/image_picker_windows/example/pubspec.yaml b/packages/image_picker/image_picker_windows/example/pubspec.yaml index 3368e8d5640..4bac1e1cef3 100644 --- a/packages/image_picker/image_picker_windows/example/pubspec.yaml +++ b/packages/image_picker/image_picker_windows/example/pubspec.yaml @@ -4,8 +4,8 @@ publish_to: 'none' version: 1.0.0 environment: - sdk: ^3.6.0 - flutter: ">=3.27.0" + sdk: ^3.7.0 + flutter: ">=3.29.0" dependencies: flutter: diff --git a/packages/image_picker/image_picker_windows/lib/image_picker_windows.dart b/packages/image_picker/image_picker_windows/lib/image_picker_windows.dart index 5fc3b063509..d14be7d8734 100644 --- a/packages/image_picker/image_picker_windows/lib/image_picker_windows.dart +++ b/packages/image_picker/image_picker_windows/lib/image_picker_windows.dart @@ -28,7 +28,7 @@ class ImagePickerWindows extends CameraDelegatingImagePickerPlatform { 'gif', 'tif', 'tiff', - 'apng' + 'apng', ]; /// List of video extensions used when picking videos @@ -41,7 +41,7 @@ class ImagePickerWindows extends CameraDelegatingImagePickerPlatform { 'webm', 'avi', 'mpeg', - 'mpg' + 'mpg', ]; /// The file selector used to prompt the user to select images or videos. @@ -64,12 +64,14 @@ class ImagePickerWindows extends CameraDelegatingImagePickerPlatform { CameraDevice preferredCameraDevice = CameraDevice.rear, }) async { final XFile? file = await getImageFromSource( - source: source, - options: ImagePickerOptions( - maxWidth: maxWidth, - maxHeight: maxHeight, - imageQuality: imageQuality, - preferredCameraDevice: preferredCameraDevice)); + source: source, + options: ImagePickerOptions( + maxWidth: maxWidth, + maxHeight: maxHeight, + imageQuality: imageQuality, + preferredCameraDevice: preferredCameraDevice, + ), + ); if (file != null) { return PickedFile(file.path); } @@ -85,9 +87,10 @@ class ImagePickerWindows extends CameraDelegatingImagePickerPlatform { Duration? maxDuration, }) async { final XFile? file = await getVideo( - source: source, - preferredCameraDevice: preferredCameraDevice, - maxDuration: maxDuration); + source: source, + preferredCameraDevice: preferredCameraDevice, + maxDuration: maxDuration, + ); if (file != null) { return PickedFile(file.path); } @@ -105,12 +108,14 @@ class ImagePickerWindows extends CameraDelegatingImagePickerPlatform { CameraDevice preferredCameraDevice = CameraDevice.rear, }) async { return getImageFromSource( - source: source, - options: ImagePickerOptions( - maxWidth: maxWidth, - maxHeight: maxHeight, - imageQuality: imageQuality, - preferredCameraDevice: preferredCameraDevice)); + source: source, + options: ImagePickerOptions( + maxWidth: maxWidth, + maxHeight: maxHeight, + imageQuality: imageQuality, + preferredCameraDevice: preferredCameraDevice, + ), + ); } // [ImagePickerOptions] options are not currently supported. If any @@ -127,10 +132,13 @@ class ImagePickerWindows extends CameraDelegatingImagePickerPlatform { case ImageSource.camera: return super.getImageFromSource(source: source); case ImageSource.gallery: - const XTypeGroup typeGroup = - XTypeGroup(label: 'Images', extensions: imageFormats); - final XFile? file = await fileSelector - .openFile(acceptedTypeGroups: [typeGroup]); + const XTypeGroup typeGroup = XTypeGroup( + label: 'Images', + extensions: imageFormats, + ); + final XFile? file = await fileSelector.openFile( + acceptedTypeGroups: [typeGroup], + ); return file; } // Ensure that there's a fallback in case a new source is added. @@ -153,14 +161,18 @@ class ImagePickerWindows extends CameraDelegatingImagePickerPlatform { switch (source) { case ImageSource.camera: return super.getVideo( - source: source, - preferredCameraDevice: preferredCameraDevice, - maxDuration: maxDuration); + source: source, + preferredCameraDevice: preferredCameraDevice, + maxDuration: maxDuration, + ); case ImageSource.gallery: - const XTypeGroup typeGroup = - XTypeGroup(label: 'Videos', extensions: videoFormats); - final XFile? file = await fileSelector - .openFile(acceptedTypeGroups: [typeGroup]); + const XTypeGroup typeGroup = XTypeGroup( + label: 'Videos', + extensions: videoFormats, + ); + final XFile? file = await fileSelector.openFile( + acceptedTypeGroups: [typeGroup], + ); return file; } // Ensure that there's a fallback in case a new source is added. @@ -177,21 +189,27 @@ class ImagePickerWindows extends CameraDelegatingImagePickerPlatform { double? maxHeight, int? imageQuality, }) async { - const XTypeGroup typeGroup = - XTypeGroup(label: 'Images', extensions: imageFormats); - final List files = await fileSelector - .openFiles(acceptedTypeGroups: [typeGroup]); + const XTypeGroup typeGroup = XTypeGroup( + label: 'Images', + extensions: imageFormats, + ); + final List files = await fileSelector.openFiles( + acceptedTypeGroups: [typeGroup], + ); return files; } @override - Future> getMultiVideoWithOptions( - {MultiVideoPickerOptions options = - const MultiVideoPickerOptions()}) async { - const XTypeGroup typeGroup = - XTypeGroup(label: 'Videos', extensions: videoFormats); - final List files = await fileSelector - .openFiles(acceptedTypeGroups: [typeGroup]); + Future> getMultiVideoWithOptions({ + MultiVideoPickerOptions options = const MultiVideoPickerOptions(), + }) async { + const XTypeGroup typeGroup = XTypeGroup( + label: 'Videos', + extensions: videoFormats, + ); + final List files = await fileSelector.openFiles( + acceptedTypeGroups: [typeGroup], + ); return files; } @@ -201,20 +219,21 @@ class ImagePickerWindows extends CameraDelegatingImagePickerPlatform { @override Future> getMedia({required MediaOptions options}) async { const XTypeGroup typeGroup = XTypeGroup( - label: 'images and videos', - extensions: [...imageFormats, ...videoFormats]); + label: 'images and videos', + extensions: [...imageFormats, ...videoFormats], + ); List files; if (options.allowMultiple) { - files = await fileSelector - .openFiles(acceptedTypeGroups: [typeGroup]); + files = await fileSelector.openFiles( + acceptedTypeGroups: [typeGroup], + ); } else { - final XFile? file = await fileSelector - .openFile(acceptedTypeGroups: [typeGroup]); - files = [ - if (file != null) file, - ]; + final XFile? file = await fileSelector.openFile( + acceptedTypeGroups: [typeGroup], + ); + files = [if (file != null) file]; } return files; } diff --git a/packages/image_picker/image_picker_windows/pubspec.yaml b/packages/image_picker/image_picker_windows/pubspec.yaml index 92e3a75717e..f7f6a6e8b54 100644 --- a/packages/image_picker/image_picker_windows/pubspec.yaml +++ b/packages/image_picker/image_picker_windows/pubspec.yaml @@ -5,8 +5,8 @@ issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+ version: 0.2.2 environment: - sdk: ^3.6.0 - flutter: ">=3.27.0" + sdk: ^3.7.0 + flutter: ">=3.29.0" flutter: plugin: diff --git a/packages/image_picker/image_picker_windows/test/image_picker_windows_test.dart b/packages/image_picker/image_picker_windows/test/image_picker_windows_test.dart index 98b4646374d..b0010c53c26 100644 --- a/packages/image_picker/image_picker_windows/test/image_picker_windows_test.dart +++ b/packages/image_picker/image_picker_windows/test/image_picker_windows_test.dart @@ -29,13 +29,17 @@ void main() { plugin = ImagePickerWindows(); mockFileSelectorPlatform = MockFileSelectorPlatform(); - when(mockFileSelectorPlatform.openFile( - acceptedTypeGroups: anyNamed('acceptedTypeGroups'))) - .thenAnswer((_) async => null); - - when(mockFileSelectorPlatform.openFiles( - acceptedTypeGroups: anyNamed('acceptedTypeGroups'))) - .thenAnswer((_) async => List.empty()); + when( + mockFileSelectorPlatform.openFile( + acceptedTypeGroups: anyNamed('acceptedTypeGroups'), + ), + ).thenAnswer((_) async => null); + + when( + mockFileSelectorPlatform.openFiles( + acceptedTypeGroups: anyNamed('acceptedTypeGroups'), + ), + ).thenAnswer((_) async => List.empty()); ImagePickerWindows.fileSelector = mockFileSelectorPlatform; }); @@ -50,47 +54,66 @@ void main() { await plugin.pickImage(source: ImageSource.gallery); final VerificationResult result = verify( - mockFileSelectorPlatform.openFile( - acceptedTypeGroups: captureAnyNamed('acceptedTypeGroups'))); - expect(capturedTypeGroups(result)[0].extensions, - ImagePickerWindows.imageFormats); + mockFileSelectorPlatform.openFile( + acceptedTypeGroups: captureAnyNamed('acceptedTypeGroups'), + ), + ); + expect( + capturedTypeGroups(result)[0].extensions, + ImagePickerWindows.imageFormats, + ); }); test('getImage passes the accepted type groups correctly', () async { await plugin.getImage(source: ImageSource.gallery); final VerificationResult result = verify( - mockFileSelectorPlatform.openFile( - acceptedTypeGroups: captureAnyNamed('acceptedTypeGroups'))); - expect(capturedTypeGroups(result)[0].extensions, - ImagePickerWindows.imageFormats); + mockFileSelectorPlatform.openFile( + acceptedTypeGroups: captureAnyNamed('acceptedTypeGroups'), + ), + ); + expect( + capturedTypeGroups(result)[0].extensions, + ImagePickerWindows.imageFormats, + ); }); test('getMultiImage passes the accepted type groups correctly', () async { await plugin.getMultiImage(); final VerificationResult result = verify( - mockFileSelectorPlatform.openFiles( - acceptedTypeGroups: captureAnyNamed('acceptedTypeGroups'))); - expect(capturedTypeGroups(result)[0].extensions, - ImagePickerWindows.imageFormats); + mockFileSelectorPlatform.openFiles( + acceptedTypeGroups: captureAnyNamed('acceptedTypeGroups'), + ), + ); + expect( + capturedTypeGroups(result)[0].extensions, + ImagePickerWindows.imageFormats, + ); }); test( - 'getImageFromSource throws StateError when source is camera with no delegate', - () async { - await expectLater(plugin.getImageFromSource(source: ImageSource.camera), - throwsStateError); - }); + 'getImageFromSource throws StateError when source is camera with no delegate', + () async { + await expectLater( + plugin.getImageFromSource(source: ImageSource.camera), + throwsStateError, + ); + }, + ); test('getMultiImage passes the accepted type groups correctly', () async { await plugin.getMultiImage(); final VerificationResult result = verify( - mockFileSelectorPlatform.openFiles( - acceptedTypeGroups: captureAnyNamed('acceptedTypeGroups'))); - expect(capturedTypeGroups(result)[0].extensions, - ImagePickerWindows.imageFormats); + mockFileSelectorPlatform.openFiles( + acceptedTypeGroups: captureAnyNamed('acceptedTypeGroups'), + ), + ); + expect( + capturedTypeGroups(result)[0].extensions, + ImagePickerWindows.imageFormats, + ); }); }); @@ -99,45 +122,65 @@ void main() { await plugin.pickVideo(source: ImageSource.gallery); final VerificationResult result = verify( - mockFileSelectorPlatform.openFile( - acceptedTypeGroups: captureAnyNamed('acceptedTypeGroups'))); - expect(capturedTypeGroups(result)[0].extensions, - ImagePickerWindows.videoFormats); + mockFileSelectorPlatform.openFile( + acceptedTypeGroups: captureAnyNamed('acceptedTypeGroups'), + ), + ); + expect( + capturedTypeGroups(result)[0].extensions, + ImagePickerWindows.videoFormats, + ); }); test('getVideo passes the accepted type groups correctly', () async { await plugin.getVideo(source: ImageSource.gallery); final VerificationResult result = verify( - mockFileSelectorPlatform.openFile( - acceptedTypeGroups: captureAnyNamed('acceptedTypeGroups'))); - expect(capturedTypeGroups(result)[0].extensions, - ImagePickerWindows.videoFormats); + mockFileSelectorPlatform.openFile( + acceptedTypeGroups: captureAnyNamed('acceptedTypeGroups'), + ), + ); + expect( + capturedTypeGroups(result)[0].extensions, + ImagePickerWindows.videoFormats, + ); }); test('getVideo calls delegate when source is camera', () async { const String fakePath = '/tmp/foo'; plugin.cameraDelegate = FakeCameraDelegate(result: XFile(fakePath)); - expect((await plugin.getVideo(source: ImageSource.camera))!.path, - fakePath); + expect( + (await plugin.getVideo(source: ImageSource.camera))!.path, + fakePath, + ); }); - test('getVideo throws StateError when source is camera with no delegate', - () async { - await expectLater( - plugin.getVideo(source: ImageSource.camera), throwsStateError); - }); + test( + 'getVideo throws StateError when source is camera with no delegate', + () async { + await expectLater( + plugin.getVideo(source: ImageSource.camera), + throwsStateError, + ); + }, + ); - test('getMultiVideoWithOptions passes the accepted type groups correctly', - () async { - await plugin.getMultiVideoWithOptions(); + test( + 'getMultiVideoWithOptions passes the accepted type groups correctly', + () async { + await plugin.getMultiVideoWithOptions(); - final VerificationResult result = verify( + final VerificationResult result = verify( mockFileSelectorPlatform.openFiles( - acceptedTypeGroups: captureAnyNamed('acceptedTypeGroups'))); - expect(capturedTypeGroups(result)[0].extensions, - ImagePickerWindows.videoFormats); - }); + acceptedTypeGroups: captureAnyNamed('acceptedTypeGroups'), + ), + ); + expect( + capturedTypeGroups(result)[0].extensions, + ImagePickerWindows.videoFormats, + ); + }, + ); }); group('media', () { @@ -145,33 +188,35 @@ void main() { await plugin.getMedia(options: const MediaOptions(allowMultiple: true)); final VerificationResult result = verify( - mockFileSelectorPlatform.openFiles( - acceptedTypeGroups: captureAnyNamed('acceptedTypeGroups'))); + mockFileSelectorPlatform.openFiles( + acceptedTypeGroups: captureAnyNamed('acceptedTypeGroups'), + ), + ); expect(capturedTypeGroups(result)[0].extensions, [ ...ImagePickerWindows.imageFormats, - ...ImagePickerWindows.videoFormats + ...ImagePickerWindows.videoFormats, ]); }); - test('multiple media handles an empty path response gracefully', - () async { - expect( + test( + 'multiple media handles an empty path response gracefully', + () async { + expect( await plugin.getMedia( - options: const MediaOptions( - allowMultiple: true, - ), + options: const MediaOptions(allowMultiple: true), ), - []); - }); + [], + ); + }, + ); test('single media handles an empty path response gracefully', () async { expect( - await plugin.getMedia( - options: const MediaOptions( - allowMultiple: false, - ), - ), - []); + await plugin.getMedia( + options: const MediaOptions(allowMultiple: false), + ), + [], + ); }); }); }); @@ -183,16 +228,18 @@ class FakeCameraDelegate extends ImagePickerCameraDelegate { XFile? result; @override - Future takePhoto( - {ImagePickerCameraDelegateOptions options = - const ImagePickerCameraDelegateOptions()}) async { + Future takePhoto({ + ImagePickerCameraDelegateOptions options = + const ImagePickerCameraDelegateOptions(), + }) async { return result; } @override - Future takeVideo( - {ImagePickerCameraDelegateOptions options = - const ImagePickerCameraDelegateOptions()}) async { + Future takeVideo({ + ImagePickerCameraDelegateOptions options = + const ImagePickerCameraDelegateOptions(), + }) async { return result; } } diff --git a/packages/image_picker/image_picker_windows/test/image_picker_windows_test.mocks.dart b/packages/image_picker/image_picker_windows/test/image_picker_windows_test.mocks.dart index 49797a9938a..ebfafe27adb 100644 --- a/packages/image_picker/image_picker_windows/test/image_picker_windows_test.mocks.dart +++ b/packages/image_picker/image_picker_windows/test/image_picker_windows_test.mocks.dart @@ -38,17 +38,14 @@ class MockFileSelectorPlatform extends _i1.Mock String? confirmButtonText, }) => (super.noSuchMethod( - Invocation.method( - #openFile, - [], - { - #acceptedTypeGroups: acceptedTypeGroups, - #initialDirectory: initialDirectory, - #confirmButtonText: confirmButtonText, - }, - ), - returnValue: _i3.Future<_i2.XFile?>.value(), - ) as _i3.Future<_i2.XFile?>); + Invocation.method(#openFile, [], { + #acceptedTypeGroups: acceptedTypeGroups, + #initialDirectory: initialDirectory, + #confirmButtonText: confirmButtonText, + }), + returnValue: _i3.Future<_i2.XFile?>.value(), + ) + as _i3.Future<_i2.XFile?>); @override _i3.Future> openFiles({ @@ -57,17 +54,14 @@ class MockFileSelectorPlatform extends _i1.Mock String? confirmButtonText, }) => (super.noSuchMethod( - Invocation.method( - #openFiles, - [], - { - #acceptedTypeGroups: acceptedTypeGroups, - #initialDirectory: initialDirectory, - #confirmButtonText: confirmButtonText, - }, - ), - returnValue: _i3.Future>.value(<_i2.XFile>[]), - ) as _i3.Future>); + Invocation.method(#openFiles, [], { + #acceptedTypeGroups: acceptedTypeGroups, + #initialDirectory: initialDirectory, + #confirmButtonText: confirmButtonText, + }), + returnValue: _i3.Future>.value(<_i2.XFile>[]), + ) + as _i3.Future>); @override _i3.Future getSavePath({ @@ -77,18 +71,15 @@ class MockFileSelectorPlatform extends _i1.Mock String? confirmButtonText, }) => (super.noSuchMethod( - Invocation.method( - #getSavePath, - [], - { - #acceptedTypeGroups: acceptedTypeGroups, - #initialDirectory: initialDirectory, - #suggestedName: suggestedName, - #confirmButtonText: confirmButtonText, - }, - ), - returnValue: _i3.Future.value(), - ) as _i3.Future); + Invocation.method(#getSavePath, [], { + #acceptedTypeGroups: acceptedTypeGroups, + #initialDirectory: initialDirectory, + #suggestedName: suggestedName, + #confirmButtonText: confirmButtonText, + }), + returnValue: _i3.Future.value(), + ) + as _i3.Future); @override _i3.Future<_i2.FileSaveLocation?> getSaveLocation({ @@ -96,16 +87,13 @@ class MockFileSelectorPlatform extends _i1.Mock _i2.SaveDialogOptions? options = const _i2.SaveDialogOptions(), }) => (super.noSuchMethod( - Invocation.method( - #getSaveLocation, - [], - { - #acceptedTypeGroups: acceptedTypeGroups, - #options: options, - }, - ), - returnValue: _i3.Future<_i2.FileSaveLocation?>.value(), - ) as _i3.Future<_i2.FileSaveLocation?>); + Invocation.method(#getSaveLocation, [], { + #acceptedTypeGroups: acceptedTypeGroups, + #options: options, + }), + returnValue: _i3.Future<_i2.FileSaveLocation?>.value(), + ) + as _i3.Future<_i2.FileSaveLocation?>); @override _i3.Future getDirectoryPath({ @@ -113,16 +101,13 @@ class MockFileSelectorPlatform extends _i1.Mock String? confirmButtonText, }) => (super.noSuchMethod( - Invocation.method( - #getDirectoryPath, - [], - { - #initialDirectory: initialDirectory, - #confirmButtonText: confirmButtonText, - }, - ), - returnValue: _i3.Future.value(), - ) as _i3.Future); + Invocation.method(#getDirectoryPath, [], { + #initialDirectory: initialDirectory, + #confirmButtonText: confirmButtonText, + }), + returnValue: _i3.Future.value(), + ) + as _i3.Future); @override _i3.Future> getDirectoryPaths({ @@ -130,14 +115,11 @@ class MockFileSelectorPlatform extends _i1.Mock String? confirmButtonText, }) => (super.noSuchMethod( - Invocation.method( - #getDirectoryPaths, - [], - { - #initialDirectory: initialDirectory, - #confirmButtonText: confirmButtonText, - }, - ), - returnValue: _i3.Future>.value([]), - ) as _i3.Future>); + Invocation.method(#getDirectoryPaths, [], { + #initialDirectory: initialDirectory, + #confirmButtonText: confirmButtonText, + }), + returnValue: _i3.Future>.value([]), + ) + as _i3.Future>); }