[image_picker] Add videoQuality parameter to pickVideo#11200
[image_picker] Add videoQuality parameter to pickVideo#11200Koichi5 wants to merge 6 commits intoflutter:mainfrom
Conversation
Adds VideoQuality enum and an optional quality parameter to getVideo in the platform interface. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Version bumps: - image_picker_platform_interface: 2.11.1 -> 2.12.0 - image_picker_android: 0.8.13+14 -> 0.8.14 - image_picker_ios: 0.8.13+6 -> 0.8.14 - image_picker_macos: 0.2.2+1 -> 0.2.3 - image_picker_linux: 0.2.2 -> 0.2.3 - image_picker_windows: 0.2.2 -> 0.2.3 - image_picker_for_web: 3.1.1 -> 3.1.2 - image_picker: 1.2.1 -> 1.3.0
FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE.
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request adds a videoQuality parameter to pickVideo across the image_picker federated plugin, allowing users to specify video recording quality. The changes span the platform interface, Android, iOS, and other platform implementations, as well as the example app. My review focuses on a few areas for improvement. There's some code duplication in the example app that could be refactored. The iOS implementation is missing tests for the new video quality feature. More critically, the videoQuality parameter is not correctly passed down to the camera delegate in the platform interface, and it's completely unused in the fallback method channel implementation, which are significant oversights.
| required ImageSource source, | ||
| CameraDevice preferredCameraDevice = CameraDevice.rear, | ||
| Duration? maxDuration, | ||
| VideoQuality quality = VideoQuality.high, | ||
| }) async { |
There was a problem hiding this comment.
The quality parameter is not passed to the cameraDelegate when source is ImageSource.camera. This means the video quality setting will be ignored for platforms that use a camera delegate (e.g., Linux, macOS, Windows).
To fix this, ImagePickerCameraDelegateOptions should be updated to include the video quality, and takeVideo in ImagePickerCameraDelegate should be updated to accept it. Then you can pass it here:
return delegate.takeVideo(
options: ImagePickerCameraDelegateOptions(
preferredCameraDevice: preferredCameraDevice,
maxVideoDuration: maxDuration,
videoQuality: quality, // Add this
),
);
...cker/image_picker_platform_interface/lib/src/method_channel/method_channel_image_picker.dart
Show resolved
Hide resolved
| if (_picker.supportsImageSource(ImageSource.camera)) | ||
| Padding( | ||
| padding: const EdgeInsets.only(top: 16.0), | ||
| child: FloatingActionButton( | ||
| backgroundColor: Colors.orange, | ||
| onPressed: () { | ||
| isVideo = true; | ||
| _onImageButtonPressed( | ||
| ImageSource.camera, | ||
| context: context, | ||
| videoQuality: VideoQuality.medium, | ||
| ); | ||
| }, | ||
| heroTag: 'takeVideoMedium', | ||
| tooltip: 'Take a video (medium quality)', | ||
| child: const Icon(Icons.videocam), | ||
| ), | ||
| ), | ||
| if (_picker.supportsImageSource(ImageSource.camera)) | ||
| Padding( | ||
| padding: const EdgeInsets.only(top: 16.0), | ||
| child: FloatingActionButton( | ||
| backgroundColor: Colors.blue, | ||
| onPressed: () { | ||
| isVideo = true; | ||
| _onImageButtonPressed( | ||
| ImageSource.camera, | ||
| context: context, | ||
| videoQuality: VideoQuality.low, | ||
| ); | ||
| }, | ||
| heroTag: 'takeVideoLow', | ||
| tooltip: 'Take a video (low quality)', | ||
| child: const Icon(Icons.videocam), | ||
| ), | ||
| ), |
There was a problem hiding this comment.
There's significant code duplication for creating the FloatingActionButtons for different video qualities. This can be refactored into a helper method to improve maintainability and readability.
For example, you could create a helper widget/method like this:
Widget _buildVideoButton({
required VideoQuality quality,
required Color color,
required String heroTag,
required String tooltip,
}) {
return Padding(
padding: const EdgeInsets.only(top: 16.0),
child: FloatingActionButton(
backgroundColor: color,
onPressed: () {
isVideo = true;
_onImageButtonPressed(
ImageSource.camera,
context: context,
videoQuality: quality,
);
},
heroTag: heroTag,
tooltip: tooltip,
child: const Icon(Icons.videocam),
),
);
}And then use it for all three buttons.
| Future<String?> pickVideo( | ||
| SourceSpecification source, | ||
| int? maxDurationSeconds, | ||
| ApiVideoQuality? videoQuality, | ||
| ) async { |
There was a problem hiding this comment.
While the fake API has been updated to accept videoQuality, there are no corresponding tests to verify that this parameter is correctly passed to the native side. The Android implementation includes such tests, and it would be good to have them here for consistency and to ensure the feature works as expected on iOS.
Please consider adding tests for:
- The default quality when
qualityis not provided. - Passing each of the
VideoQualityenum values.
|
Thanks for the contribution! We won't be able to review this PR until the CLA check is passing. If you are the author of all of the code in the PR, per the CLA requirements, the commit authorship will need to reflect that. |
Description
Adds a
videoQualityparameter topickVideoacross the image_picker federation, allowing apps to specify video recording quality (low,medium,high).This is a combination PR for the following individual changes:
VideoQualityenum andgetVideoparameterpickVideovideoQualityparameter + example app demoAddresses flutter/flutter#179940
Changes
image_picker_platform_interfaceVideoQualityenum,getVideovideoQualityparamimage_picker_androidCamcorderProfileimage_picker_iosUIImagePickerControllerQualityTypeimage_picker_macosimage_picker_linuximage_picker_windowsimage_picker_for_webimage_pickerpickVideovideoQualityparameterPre-Review Checklist
[shared_preferences]///).