允许用户在不使用自动旋转的情况下向右和向左横向移动

时间:2019-12-04 11:27:46

标签: android flutter flutter-layout

我尝试使用SystemChrome来更改方向,它适用于Lock ScreenOrientation。但是正如我提供的两个方向。应用程序将采用第一个方向,直到用户从“设置”启动“自动方向”为止。

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

是否可以允许用户在不使用自动方向服务的情况下更改方向?

3 个答案:

答案 0 :(得分:0)

它仅适用于android设备: 在AndroidManifest.xml

中向主要活动添加属性
<activity
    android:screenOrientation="sensorLandscape"
    ...

,现在屏幕将保持横向显示,但根据设备传感器的不同,可以是正向或反向横向显示。即使用户已锁定基于传感器的旋转,也会使用该传感器。

答案 1 :(得分:0)

这里的想法是使用make传感器插件仅获取屏幕方向横向信息。即使用户锁定方向,传感器也可以工作。

https://www.techrepublic.com/article/pro-tip-use-android-sensors-to-detect-orientation-changes/

在颤抖的站点上,将侦听器放在某个位置,然后通过setPreferredOrientations方法以编程方式进行旋转。

https://master-api.flutter.dev/flutter/services/SystemChrome/setPreferredOrientations.html

答案 2 :(得分:0)

嘿@Ashish,我为您找到了一个有关定向功能和概念的链接

SystemChrome.setPreferredOrientation