Stream<NativeDeviceOrientation> onOrientationChanged(useSensor: false)
,即使你使用SystemChrome.setPreferredOrientations()
锁定屏幕,也会触发方向变化。_orientation = NativeDeviceOrientationCommunicator()
.onOrientationChanged(useSensor: true)
.listen((event) {
switch (event) {
case NativeDeviceOrientation.portraitUp:
case NativeDeviceOrientation.unknown:
_actualOrientation = DeviceOrientation.portraitUp;
break;
case NativeDeviceOrientation.portraitDown:
_actualOrientation = DeviceOrientation.portraitDown;
break;
case NativeDeviceOrientation.landscapeLeft:
_actualOrientation = DeviceOrientation.landscapeLeft;
break;
case NativeDeviceOrientation.landscapeRight:
_actualOrientation = DeviceOrientation.landscapeRight;
break;
}
});
_orientation.cancel();