setOrientation method

  1. @override
Future<void> setOrientation(
  1. String method, {
  2. bool forceSensor = false,
})
override

Sets the screen orientation. This method must be implemented by all concrete platforms. 设置屏幕方向。所有具体平台必须实现此方法。

Implementation

@override
Future<void> setOrientation(String method, {bool forceSensor = false}) async {
  // Check if the current platform is supported.
  // 检查当前平台是否受支持。
  if (defaultTargetPlatform != TargetPlatform.android && defaultTargetPlatform != TargetPlatform.iOS) {
    // Return early for unsupported platforms to do nothing.
    // 对于不支持的平台,提前返回不做任何操作。
    return;
  }

  // Passes the 'forceSensor' argument if the method supports it, otherwise calls without arguments.
  // 如果方法支持 forceSensor,则传递参数,否则直接调用。
  final args = {'forceSensor': forceSensor};
  if (method == 'setPortraitAuto' || method == 'setLandscapeAuto' || method == 'setAuto') {
    await methodChannel.invokeMethod<void>(method, args);
  } else {
    await methodChannel.invokeMethod<void>(method);
  }
}