setRotation method

  1. @override
Future<void> setRotation(
  1. OutputRotation rotation
)
override

Set the rotation of the output relative to the natural orientation of the device.

E.g. The natural orientation of a phone is typically portrait up.

Implementation

@override
Future<void> setRotation(OutputRotation rotation) async {
  verifyAttached();
  final CaptureConnection? connection =
      await capturePhotoOutput.connectionWithMediaType(MediaType.video);

  if (connection == null) {
    throw StateError(
      'Could not find a connection for this output. This may not be attached to a CameraController.',
    );
  }

  switch (rotation) {
    case OutputRotation.rotation0:
      return connection.setVideoOrientation(CaptureVideoOrientation.portrait);
    case OutputRotation.rotation90:
      return connection.setVideoOrientation(
        CaptureVideoOrientation.landscapeLeft,
      );
    case OutputRotation.rotation180:
      return connection.setVideoOrientation(
        CaptureVideoOrientation.portraitUpsideDown,
      );
    case OutputRotation.rotation270:
      return connection.setVideoOrientation(
        CaptureVideoOrientation.landscapeRight,
      );
  }
}