user1087973
user1087973

Reputation: 1128

Flutter camera plugin prevent orientation change?

Using the latest version 0.8.1, is there a way to prevent orientation change? I have locked the device orientation using SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); but if I rotate the device to landscape, the camera also attempts to rotate and the preview looks compressed. A good example would be the instagram camera, which is locked to portrait mode. If you rotate your device the preview doesn't move at all.

Upvotes: 2

Views: 12257

Answers (3)

You can apply lock on capture orientation this will also used for app being crashed during camera initialisation

await _cameraController.initialize();
await _cameraController.lockCaptureOrientation();

Upvotes: 8

user1087973
user1087973

Reputation: 1128

I must have missed it in the documentation (or it's been left out), but as of version 0.7.0 there is a lock method:

<CameraController>.lockCaptureOrientation(DeviceOrientation);

Upvotes: 1

Zero
Zero

Reputation: 2940

Orientation orientation = MediaQuery.of(context).orientation;
SystemChrome.setPreferredOrientations(orientation == Orientation.portrait
    ? [
        DeviceOrientation.portraitDown,
        DeviceOrientation.portraitUp,
      ]
    : [
        DeviceOrientation.landscapeLeft,
        DeviceOrientation.landscapeRight,
      ]);

Upvotes: -2

Related Questions