lockCaptureOrientation method Null safety
- int cameraId,
- DeviceOrientation orientation
override
Locks the capture orientation.
Implementation
@override
Future<void> lockCaptureOrientation(
int cameraId,
DeviceOrientation orientation,
) async {
try {
final html.ScreenOrientation? screenOrientation =
window?.screen?.orientation;
final html.Element? documentElement = window?.document.documentElement;
if (screenOrientation != null && documentElement != null) {
final String orientationType =
_cameraService.mapDeviceOrientationToOrientationType(orientation);
// Full-screen mode may be required to modify the device orientation.
// See: https://w3c.github.io/screen-orientation/#interaction-with-fullscreen-api
// Recent versions of Dart changed requestFullscreen to return a Future instead of void.
// This wrapper allows use of both the old and new APIs.
dynamic fullScreen() => documentElement.requestFullscreen();
await fullScreen();
await screenOrientation.lock(orientationType);
} else {
throw PlatformException(
code: CameraErrorCode.orientationNotSupported.toString(),
message: 'Orientation is not supported in the current browser.',
);
}
} on html.DomException catch (e) {
throw PlatformException(code: e.name, message: e.message);
}
}