From bca3cccb0e6e42cb4c07be9974501c34361cae25 Mon Sep 17 00:00:00 2001 From: Camille Simon Date: Wed, 25 Jun 2025 15:17:57 -0700 Subject: [PATCH 1/5] debugging + posisble solution --- .../camera_android_camerax/example/lib/main.dart | 3 +++ .../lib/src/android_camera_camerax.dart | 10 ++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/camera/camera_android_camerax/example/lib/main.dart b/packages/camera/camera_android_camerax/example/lib/main.dart index 359f584fd765..3b6d620c4be9 100644 --- a/packages/camera/camera_android_camerax/example/lib/main.dart +++ b/packages/camera/camera_android_camerax/example/lib/main.dart @@ -221,6 +221,9 @@ class _CameraExampleHomeState extends State /// Display the thumbnail of the captured image or video. Widget _thumbnailWidget() { + print( + 'CAMILLE: current device orientation -- ${controller?.value.deviceOrientation}', + ); final VideoPlayerController? localVideoController = videoController; return Expanded( diff --git a/packages/camera/camera_android_camerax/lib/src/android_camera_camerax.dart b/packages/camera/camera_android_camerax/lib/src/android_camera_camerax.dart index 795a87472278..97906c57f25c 100644 --- a/packages/camera/camera_android_camerax/lib/src/android_camera_camerax.dart +++ b/packages/camera/camera_android_camerax/lib/src/android_camera_camerax.dart @@ -392,7 +392,8 @@ class AndroidCameraCameraX extends CameraPlatform { // Configure ImageCapture instance. imageCapture = proxy.newImageCapture( resolutionSelector: presetResolutionSelector, - /* use CameraX default target rotation */ targetRotation: null, + /* use CameraX default target rotation */ targetRotation: + await deviceOrientationManager.getDefaultDisplayRotation(), ); // Configure ImageAnalysis instance. @@ -431,6 +432,7 @@ class AndroidCameraCameraX extends CameraPlatform { .toDouble(); sensorOrientationDegrees = cameraDescription.sensorOrientation.toDouble(); + print('CAMILLE: sensorOrientationDegrees: $sensorOrientationDegrees'); _handlesCropAndRotation = await preview!.surfaceProducerHandlesCropAndRotation(); _initialDeviceOrientation = _deserializeDeviceOrientation( @@ -966,9 +968,9 @@ class AndroidCameraCameraX extends CameraPlatform { await imageCapture!.setFlashMode(CameraXFlashMode.off); } - // Set target rotation to default CameraX rotation only if capture - // orientation not locked. - if (!captureOrientationLocked && shouldSetDefaultRotation) { + // Set target rotation to the current default CameraX rotation if + // the capture orientation is not locked. + if (!captureOrientationLocked) { await imageCapture!.setTargetRotation( await deviceOrientationManager.getDefaultDisplayRotation(), ); From 990c32b280a9c574166d930b431219256f2dd624 Mon Sep 17 00:00:00 2001 From: Camille Simon Date: Wed, 25 Jun 2025 16:52:58 -0700 Subject: [PATCH 2/5] id failing tesT --- packages/camera/camera_android_camerax/example/lib/main.dart | 3 --- .../lib/src/android_camera_camerax.dart | 1 - .../test/android_camera_camerax_test.dart | 4 +++- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/camera/camera_android_camerax/example/lib/main.dart b/packages/camera/camera_android_camerax/example/lib/main.dart index 3b6d620c4be9..359f584fd765 100644 --- a/packages/camera/camera_android_camerax/example/lib/main.dart +++ b/packages/camera/camera_android_camerax/example/lib/main.dart @@ -221,9 +221,6 @@ class _CameraExampleHomeState extends State /// Display the thumbnail of the captured image or video. Widget _thumbnailWidget() { - print( - 'CAMILLE: current device orientation -- ${controller?.value.deviceOrientation}', - ); final VideoPlayerController? localVideoController = videoController; return Expanded( diff --git a/packages/camera/camera_android_camerax/lib/src/android_camera_camerax.dart b/packages/camera/camera_android_camerax/lib/src/android_camera_camerax.dart index 97906c57f25c..e52435b3b100 100644 --- a/packages/camera/camera_android_camerax/lib/src/android_camera_camerax.dart +++ b/packages/camera/camera_android_camerax/lib/src/android_camera_camerax.dart @@ -432,7 +432,6 @@ class AndroidCameraCameraX extends CameraPlatform { .toDouble(); sensorOrientationDegrees = cameraDescription.sensorOrientation.toDouble(); - print('CAMILLE: sensorOrientationDegrees: $sensorOrientationDegrees'); _handlesCropAndRotation = await preview!.surfaceProducerHandlesCropAndRotation(); _initialDeviceOrientation = _deserializeDeviceOrientation( diff --git a/packages/camera/camera_android_camerax/test/android_camera_camerax_test.dart b/packages/camera/camera_android_camerax/test/android_camera_camerax_test.dart index 6618e45f26f7..27f33259cf98 100644 --- a/packages/camera/camera_android_camerax/test/android_camera_camerax_test.dart +++ b/packages/camera/camera_android_camerax/test/android_camera_camerax_test.dart @@ -3531,7 +3531,9 @@ void main() { // Orientation is unlocked and plugin does not need to set default target // rotation manually. await camera.takePicture(cameraId); - verifyNever(mockImageCapture.setTargetRotation(any)); + verifyNever( + mockImageCapture.setTargetRotation(any), + ); // TODO(camsim99): fix // Orientation is locked and plugin does not need to set default target // rotation manually. From 9e7730c69f52d6555420464fdd91f576e75c33a8 Mon Sep 17 00:00:00 2001 From: Camille Simon Date: Thu, 26 Jun 2025 11:26:43 -0700 Subject: [PATCH 3/5] fix test --- .../test/android_camera_camerax_test.dart | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/camera/camera_android_camerax/test/android_camera_camerax_test.dart b/packages/camera/camera_android_camerax/test/android_camera_camerax_test.dart index 27f33259cf98..6b2535cf437e 100644 --- a/packages/camera/camera_android_camerax/test/android_camera_camerax_test.dart +++ b/packages/camera/camera_android_camerax/test/android_camera_camerax_test.dart @@ -3488,7 +3488,7 @@ void main() { ); test( - 'takePicture sets ImageCapture target rotation to currrent photo rotation when orientation unlocked', + 'takePicture sets ImageCapture target rotation as expected when orientation locked or unlocked', () async { final AndroidCameraCameraX camera = AndroidCameraCameraX(); final MockImageCapture mockImageCapture = MockImageCapture(); @@ -3531,9 +3531,7 @@ void main() { // Orientation is unlocked and plugin does not need to set default target // rotation manually. await camera.takePicture(cameraId); - verifyNever( - mockImageCapture.setTargetRotation(any), - ); // TODO(camsim99): fix + verify(mockImageCapture.setTargetRotation(defaultTargetRotation)); // Orientation is locked and plugin does not need to set default target // rotation manually. From 09c892000f12955b4758454d0c942961fcabc2ee Mon Sep 17 00:00:00 2001 From: Camille Simon Date: Thu, 26 Jun 2025 11:28:21 -0700 Subject: [PATCH 4/5] bump version --- packages/camera/camera_android_camerax/CHANGELOG.md | 5 +++++ packages/camera/camera_android_camerax/pubspec.yaml | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/camera/camera_android_camerax/CHANGELOG.md b/packages/camera/camera_android_camerax/CHANGELOG.md index a7f96f80cfb2..795e8fc3397a 100644 --- a/packages/camera/camera_android_camerax/CHANGELOG.md +++ b/packages/camera/camera_android_camerax/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.6.20 + +* Changes target rotation of captured images to current defualt display rotation to fix captured + photo orientation to upright. + ## 0.6.19 * Ensures that a new surface is provided every time that one is requested to render the camera preview diff --git a/packages/camera/camera_android_camerax/pubspec.yaml b/packages/camera/camera_android_camerax/pubspec.yaml index 09d8688b3231..b3852a0e5fd8 100644 --- a/packages/camera/camera_android_camerax/pubspec.yaml +++ b/packages/camera/camera_android_camerax/pubspec.yaml @@ -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.6.19 +version: 0.6.20 environment: sdk: ^3.7.0 From da98bdf1dae69e5f203c9c985f962cc5162846b4 Mon Sep 17 00:00:00 2001 From: Camille Simon <43054281+camsim99@users.noreply.github.com> Date: Thu, 26 Jun 2025 15:40:19 -0700 Subject: [PATCH 5/5] Update packages/camera/camera_android_camerax/CHANGELOG.md Co-authored-by: Gray Mackall <34871572+gmackall@users.noreply.github.com> --- packages/camera/camera_android_camerax/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/camera/camera_android_camerax/CHANGELOG.md b/packages/camera/camera_android_camerax/CHANGELOG.md index bcff5bfd762b..be0982077530 100644 --- a/packages/camera/camera_android_camerax/CHANGELOG.md +++ b/packages/camera/camera_android_camerax/CHANGELOG.md @@ -1,6 +1,6 @@ ## 0.6.19 -* Changes target rotation of captured images to current defualt display rotation to fix captured +* Changes target rotation of captured images to current default display rotation to fix captured photo orientation to upright. ## 0.6.18+3