简体   繁体   English

Flutter 应用程序方向从纵向变为横向

[英]Flutter app orientation changes from portrait to landscape

When I load my flutter app which uses " scan: ^1.6.0 " package once the scanner gets mounted my app shifts orientation from portrait to landscape this only happens in tablet mode where the orientation is fixed to landscape mode,On the mobile app I do not face this issue, I have also set the screenOrientation to landscape in the AndroidManifest.xml file.当我加载我的 flutter 应用程序时,它使用“扫描:^1.6.0” package 一旦安装了扫描仪,我的应用程序就会将方向从纵向转换为横向这只发生在平板电脑模式下,方向固定为横向模式,在移动应用程序上我不要遇到这个问题,我还在 AndroidManifest.xml 文件中将屏幕方向设置为横向。

AndroidManifest.xml AndroidManifest.xml

main.dart主要.dart

The creator forced the orientation on native platforms, to change this on Android, you need change on native, I tried, but will need change the design, because is not reponsive and dont work on landscape.创建者强制在本机平台上设置方向,要在 Android 上更改此设置,您需要在本机上进行更改,我试过了,但需要更改设计,因为它没有响应并且不能在横向上工作。

The code that force the orientation.强制方向的代码。 You can see the complete code in android/src/main/java/com/chavesgu/scan/ScanViewNew.java完整代码可以在android/src/main/java/com/chavesgu/scan/ScanViewNew.java

public ScanViewNew(
  Context context, 
  Activity activity, 
  @NonNull ActivityPluginBinding activityPluginBinding,
  @Nullable Map<String, Object> args,
) {
  super(context, null);

  this.context = context;
  this.activity = activity;
  
  // This line force the orientation
  activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
  
  this.activityPluginBinding = activityPluginBinding;
  activityPluginBinding.addRequestPermissionsResultListener(this);
  this.scale = (double) args.get("scale");

  checkPermission();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM