lockCaptureOrientation method Null safety

  1. @override
Future<void> lockCaptureOrientation(
  1. int cameraId,
  2. DeviceOrientation orientation

Locks the capture orientation.


Future<void> lockCaptureOrientation(
  int cameraId,
  DeviceOrientation orientation,
) async {
  try {
    final html.ScreenOrientation? screenOrientation =
    final html.Element? documentElement = window?.document.documentElement;

    if (screenOrientation != null && documentElement != null) {
      final String orientationType =

      // 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);