Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
[camera] Fix preview pause orientation (#5209)
Browse files Browse the repository at this point in the history
  • Loading branch information
cassioso authored May 11, 2022
1 parent 3993fa7 commit ff01c1d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
4 changes: 4 additions & 0 deletions packages/camera/camera/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.9.4+24

* Fixes preview orientation when pausing preview with locked orientation.

## 0.9.4+23

* Minor fixes for new analysis options.
Expand Down
8 changes: 4 additions & 4 deletions packages/camera/camera/lib/src/camera_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,8 @@ class CameraController extends ValueNotifier<CameraValue> {
await CameraPlatform.instance.pausePreview(_cameraId);
value = value.copyWith(
isPreviewPaused: true,
previewPauseOrientation:
Optional<DeviceOrientation>.of(value.deviceOrientation));
previewPauseOrientation: Optional<DeviceOrientation>.of(
value.lockedCaptureOrientation ?? value.deviceOrientation));
} on PlatformException catch (e) {
throw CameraException(e.code, e.message);
}
Expand Down Expand Up @@ -520,7 +520,7 @@ class CameraController extends ValueNotifier<CameraValue> {
value = value.copyWith(
isRecordingVideo: true,
isRecordingPaused: false,
recordingOrientation: Optional<DeviceOrientation>.fromNullable(
recordingOrientation: Optional<DeviceOrientation>.of(
value.lockedCaptureOrientation ?? value.deviceOrientation));
} on PlatformException catch (e) {
throw CameraException(e.code, e.message);
Expand Down Expand Up @@ -762,7 +762,7 @@ class CameraController extends ValueNotifier<CameraValue> {
await CameraPlatform.instance.lockCaptureOrientation(
_cameraId, orientation ?? value.deviceOrientation);
value = value.copyWith(
lockedCaptureOrientation: Optional<DeviceOrientation>.fromNullable(
lockedCaptureOrientation: Optional<DeviceOrientation>.of(
orientation ?? value.deviceOrientation));
} on PlatformException catch (e) {
throw CameraException(e.code, e.message);
Expand Down
2 changes: 1 addition & 1 deletion packages/camera/camera/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: A Flutter plugin for controlling the camera. Supports previewing
Dart.
repository: https://github.com/flutter/plugins/tree/main/packages/camera/camera
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
version: 0.9.4+23
version: 0.9.4+24

environment:
sdk: ">=2.14.0 <3.0.0"
Expand Down
25 changes: 25 additions & 0 deletions packages/camera/camera/test/camera_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
import 'package:quiver/core.dart';

List<CameraDescription> get mockAvailableCameras => <CameraDescription>[
const CameraDescription(
Expand Down Expand Up @@ -1180,6 +1181,30 @@ void main() {
expect(cameraController.value.isPreviewPaused, equals(true));
});

test(
'pausePreview() sets previewPauseOrientation according to locked orientation',
() async {
final CameraController cameraController = CameraController(
const CameraDescription(
name: 'cam',
lensDirection: CameraLensDirection.back,
sensorOrientation: 90),
ResolutionPreset.max);
await cameraController.initialize();
cameraController.value = cameraController.value.copyWith(
isPreviewPaused: false,
deviceOrientation: DeviceOrientation.portraitUp,
lockedCaptureOrientation:
Optional<DeviceOrientation>.of(DeviceOrientation.landscapeRight));

await cameraController.pausePreview();

expect(cameraController.value.deviceOrientation,
equals(DeviceOrientation.portraitUp));
expect(cameraController.value.previewPauseOrientation,
equals(DeviceOrientation.landscapeRight));
});

test('pausePreview() throws $CameraException on $PlatformException',
() async {
final CameraController cameraController = CameraController(
Expand Down

0 comments on commit ff01c1d

Please sign in to comment.