首页 > 解决方案 > Flutter 中的本机设备方向问题

问题描述

我正在使用 Flutter,并且正在使用Native Device Orientation Plugin

我正在尝试了解设备方向并据此管理我的视图。

该插件工作得非常好,但是当我在A有一个的页面NativeDeviceOrientationReader并转到B有另一个NativeDeviceOrientationReader.

在这种情况下,即使我没有改变中间的方向,应该有的页面NativeDeviceOrientation.landscapeLeft也会有。NativeDeviceOrientation.landscapeRight

注意:如果我在更改页面后旋转手机,它开始正常工作。此外,如果我删除其中一个,NativeDeviceOrientationReader's它也可以正常工作。

我正在使用这段代码:

NativeDeviceOrientationReader(
    builder: (context) {
    NativeDeviceOrientation orientation = NativeDeviceOrientationReader.orientation(context);
    var quarterTurns = 0;
    if (orientation == NativeDeviceOrientation.landscapeLeft) {
          quarterTurns = 3;
     } else if (orientation == NativeDeviceOrientation.landscapeRight) {
          quarterTurns = 1;
     }
  }
),

(...)

我不知道我是否必须以某种方式关闭阅读器或其他东西。

提前致谢 !

-------------- 编辑 1 --------------

其实我没有解决这个问题,但是我可以解决我的问题,将一个更改NativeOrientationReader为 flutter OrientationBuilder,因为我意识到我不需要当前的旋转,我只想知道手机是横向还是纵向。

谢谢你。

标签: flutterdartorientationlandscapeportrait

解决方案


推荐阅读