flutter - 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
,因为我意识到我不需要当前的旋转,我只想知道手机是横向还是纵向。
谢谢你。
解决方案
推荐阅读
- swift - 无法分配给仅获取对象的“localVc”属性?
- sql - SQL BigQuery - 如何将日期(2020-11-14 16:04:15 UTC)转换为 WEEKDAY 值(0-6)
- java - 我无法使用 HttpSession 保存会话属性
- javascript - 当两边都被某个字符串包围时试图排除匹配
- ios - SwiftUI List: Move and sort items without default button in iOS 15
- amazon - Amazon Forecast Validation
- angular - 如何使用 antd for angular 将表格中的分页位置更改为居中?
- haskell - How to call a function inside the code to return the degree of a polynomial?
- javascript - problem with javascript array assignment, how can " == true : false" working in this code?
- javascript - 如果某些字符无法通过字体呈现,我如何在纯 JavaScript 中找出?