【问题标题】:How to Set landscape orientation for tablet?如何为平板电脑设置横向?
【发布时间】:2020-12-24 12:41:44
【问题描述】:

我正在尝试在运行我的应用程序后为平板电脑设置横向方向,始终以纵向模式运行,这就是我所做的:

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  // Set landscape orientation
  SystemChrome.setPreferredOrientations([
    DeviceOrientation.landscapeLeft,
    DeviceOrientation.landscapeRight,
  ]);
  runApp(MyApp());
}

【问题讨论】:

    标签: flutter widget


    【解决方案1】:

    在materialApp之前添加这个类型

      Widget build(BuildContext context) {
            SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeRight]);
            return MaterialApp();
    

    【讨论】:

    • 然后关闭您的应用并重新启动您的应用。这是为我工作的兄弟
    • 是的,我也这样做了,它可以在手机上使用,但不能在平板电脑上使用
    【解决方案2】:

    显然,方向不适用于 Nexus 9 API R 模拟器 平板电脑,但在 Pixel C API R 模拟器Nexus 7 2012 API 上运行良好R 平板电脑

    【讨论】:

      【解决方案3】:

      有两种情况,

      1. 为整个应用设置方向,永远不要让用户改变方向。- 你必须在 AndroidManifest.xml 文件的 FlutterActivity 中设置android:screenOrientation="landscape"

      2. 首先将方向设置为横向,然后根据用户的需要进行更改。-

      SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeLeft,DeviceOrientation.landscapeRight])
      

      将进入 Main AppState Management 类。

      【讨论】:

      • 谢谢,我这样做了,但它不适用于 Nexus 9 API R 模拟器平板电脑
      • 查看this
      猜你喜欢
      • 2013-09-12
      • 1970-01-01
      • 2012-03-08
      • 1970-01-01
      • 2019-10-05
      • 2017-11-24
      • 2012-04-04
      • 2011-08-12
      • 2014-10-27
      相关资源
      最近更新 更多