setRotation method
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) {
verifyAttached();
late final int angle;
switch (rotation) {
case OutputRotation.rotation0:
angle = 0;
break;
case OutputRotation.rotation90:
throw UnsupportedError('This rotation is not supported by this API.');
case OutputRotation.rotation180:
angle = 180;
break;
case OutputRotation.rotation270:
angle = 270;
break;
}
late int displayOrientation;
final CameraInfo cameraInfo = _controller.device.info;
if (cameraInfo.facing == CameraInfo.cameraFacingFront) {
displayOrientation = (cameraInfo.orientation + angle) % 360;
displayOrientation = (360 - displayOrientation) % 360;
} else {
displayOrientation = (cameraInfo.orientation - angle + 360) % 360;
}
return _controller.camera.setDisplayOrientation(displayOrientation);
}