Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

Limatationz
Copy link

Hey,

I noticed that the existing lensType property in CameraDescription is currently not set in camera_avfoundation. But for identifying the cameras (in particular the back ones) this is essential. The name of the camera cannot to this correctly.

fixes #174982

Pre-Review Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. 2 3

Copy link

google-cla bot commented Sep 5, 2025

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.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds the lensType to CameraDescription to allow for better camera identification on iOS. The changes span across the native Swift/Objective-C code, the Pigeon message definitions, the Dart platform implementation, and the example app. The core logic correctly maps AVCaptureDevice.DeviceType to the new lensType enum. The tests have also been updated to cover this new property.

My review has identified a few issues that need to be addressed: a build-breaking error in the Pigeon definition, a syntax error in a test file, an incorrect mock implementation, and a leftover debug print statement. After these are fixed, the PR should be in good shape.

@@ -121,6 +127,7 @@ final class AvailableCamerasTest: XCTestCase {
let unspecifiedCamera = MockCaptureDevice()
unspecifiedCamera.uniqueID = "0"
unspecifiedCamera.position = .unspecified
unspecifiedCamera.deviceType =

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

This line contains a syntax error and will cause a compilation failure. It seems like an incomplete assignment. To test the .unknown lens type mapping, you could assign a device type that is not explicitly handled in the CameraPlugin's switch statement, for example .builtInDualCamera.

Suggested change
unspecifiedCamera.deviceType =
unspecifiedCamera.deviceType = .builtInDualCamera

Comment on lines +84 to +85
/// The type of the camera lense
final PlatformCameraLensType lensType;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The PlatformCameraDescription class is missing the new lensType field in its constructor. Since lensType is a final field, it must be initialized. Please update the constructor to PlatformCameraDescription({required this.name, required this.lensDirection, required this.lensType}); and then re-run the pigeon generator.

@@ -32,6 +32,7 @@ class MockCaptureDevice: NSObject, FLTCaptureDevice {

var uniqueID = ""
var position = AVCaptureDevice.Position.unspecified
var deviceType: AVCaptureDevice.DeviceType? = nil

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The deviceType property is declared as optional (AVCaptureDevice.DeviceType?), but the FLTCaptureDevice protocol it conforms to defines it as a non-optional property. This mismatch can lead to runtime errors. Please make it non-optional and provide a default value to align with the protocol.

Suggested change
var deviceType: AVCaptureDevice.DeviceType? = nil
var deviceType: AVCaptureDevice.DeviceType = .builtInWideAngleCamera

@@ -157,10 +157,24 @@ extension CameraPlugin: FCPCameraApi {
@unknown default:
lensFacing = .external
}
print(device.deviceType)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This print statement appears to be for debugging purposes and should be removed before merging.

@stuartmorgan-g
Copy link
Collaborator

Thanks for the contribution! You’ve checked boxes in the PR checklist above that are not reflected in this PR, so I’m assuming this is a work in progress and am marking it as a Draft. Please review the checklist, updating the PR as appropriate, and when the state of the PR as posted reflects the checklist please feel free to mark it as ready for review.

@stuartmorgan-g stuartmorgan-g marked this pull request as draft September 5, 2025 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[camera_avfoundation] lensType is not set on iOS
2 participants