Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/camera/camera_android_camerax/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.7.2+2

* Fixes a `StateError` ("Bad state: No element") in `setFocusMode(FocusMode.auto)`
when the current focus and metering action has no auto-focus points.

## 0.7.2+1

* Migrates to Built-in Kotlin to support AGP 9.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -632,9 +632,12 @@ class AndroidCameraCameraX extends CameraPlatform {
case FocusMode.auto:
// Determine auto-focus point to restore, if any. We do not restore
// default auto-focus point if set previously to lock focus.
final MeteringPoint? unLockedFocusPoint = _defaultFocusPointLocked
final List<MeteringPoint> possibleCurrentAfPoints =
currentFocusMeteringAction?.meteringPointsAf ?? [];
final MeteringPoint? unLockedFocusPoint =
_defaultFocusPointLocked || possibleCurrentAfPoints.isEmpty
? null
: currentFocusMeteringAction!.meteringPointsAf.first;
: possibleCurrentAfPoints.first;
_defaultFocusPointLocked = false;
autoFocusPoint = unLockedFocusPoint;
disableAutoCancel = false;
Expand Down
2 changes: 1 addition & 1 deletion packages/camera/camera_android_camerax/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: camera_android_camerax
description: Android implementation of the camera plugin using the CameraX library.
repository: https://github.com/flutter/packages/tree/main/packages/camera/camera_android_camerax
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
version: 0.7.2+1
version: 0.7.2+2

environment:
sdk: ^3.12.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4967,6 +4967,44 @@ void main() {
},
);

test(
'setFocusMode does not throw when setting auto-focus mode and the current focus and metering action has no auto-focus point',
() async {
final camera = AndroidCameraCameraX();
const cameraId = 11;
final mockCameraControl = MockCameraControl();
final FocusMeteringResult mockFocusMeteringResult = MockFocusMeteringResult();
final mockCamera2CameraControl = MockCamera2CameraControl();
const point = Point<double>(0.1, 0.2);

// Set directly for test versus calling createCamera.
camera.cameraInfo = MockCameraInfo();
camera.cameraControl = mockCameraControl;

when(
mockCamera2CameraControl.addCaptureRequestOptions(any),
).thenAnswer((_) async => Future.value());

setUpOverridesForSettingFocusandExposurePoints(mockCameraControl, mockCamera2CameraControl);

// Make setting focus and metering action successful for test.
when(mockFocusMeteringResult.isFocusSuccessful).thenReturn(true);
when(
mockCameraControl.startFocusAndMetering(any),
).thenAnswer((_) async => Future.value(mockFocusMeteringResult));

// Lock focus while an auto-focus point exists, then clear it, leaving a
// non-null action whose auto-focus point list is empty.
await camera.setExposurePoint(cameraId, point);
await camera.setFocusPoint(cameraId, point);
await camera.setFocusMode(cameraId, FocusMode.locked);
await camera.setFocusPoint(cameraId, null);

// Switching back to auto-focus must not throw.
await expectLater(camera.setFocusMode(cameraId, FocusMode.auto), completes);
},
);

test(
'setFocusMode starts expected focus and metering action with previously set auto-focus point if setting locked focus mode and current focus and metering action has auto-focus point',
() async {
Expand Down