Skip to content

[camera_android_camerax] Fix setFocusMode(auto) crash when there is no auto-focus point#11884

Open
motucraft wants to merge 1 commit into
flutter:mainfrom
motucraft:fix/camera-setfocusmode-auto-empty-af-points
Open

[camera_android_camerax] Fix setFocusMode(auto) crash when there is no auto-focus point#11884
motucraft wants to merge 1 commit into
flutter:mainfrom
motucraft:fix/camera-setfocusmode-auto-empty-af-points

Conversation

@motucraft

@motucraft motucraft commented Jun 11, 2026

Copy link
Copy Markdown

Adds the missing isEmpty guard to the FocusMode.auto branch of AndroidCameraCameraX.setFocusMode, which read meteringPointsAf.first unconditionally and threw StateError: Bad state: No element when the current focus-and-metering action had no auto-focus point.

The FocusMode.locked branch already guards this; the auto branch did not.

Fixes flutter/flutter#187782

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

@motucraft motucraft changed the title [camera_android_camerax] Fixes setFocusMode(auto) crash when there is no auto-focus point [camera_android_camerax] Fix setFocusMode(auto) crash when there is no auto-focus point Jun 11, 2026
@motucraft motucraft marked this pull request as ready for review June 11, 2026 02:42

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

Copy link
Copy Markdown

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 fixes a StateError in setFocusMode(FocusMode.auto) when the current focus and metering action has no auto-focus points. The implementation safely retrieves the list of auto-focus points and checks if it is empty before accessing the first element. A unit test has been added to verify this behavior, and the package version has been bumped to 0.7.2+2. There are no review comments to address.

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] setFocusMode(FocusMode.auto) throws "StateError: Bad state: No element" when the focus-metering action has no AF points

1 participant