【发布时间】:2020-01-29 00:27:47
【问题描述】:
在主菜单屏幕上,我调用forcePortrait(),即:
static Future forcePortrait() async {
await SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
}
然后...我从主菜单屏幕中调用以下内容:
Navigator.push(context, MaterialPageRoute(builder: (context) => ScreenBoard()));
在董事会屏幕中,我拨打UScreen.forceLandscape()如下
class ScreenBoard extends StatefulWidget {
@override
_ScreenBoardState createState() => _ScreenBoardState();
}
class _ScreenBoardState extends State<ScreenBoard> {
@override
Widget build(BuildContext context) {
UScreen.forceLandscape();
return Scaffold(
backgroundColor: AppColors.redBckgnd,
body: Container(
),
);
}
}
这是forceLandscape() method
static void forceLandscape() async {
await SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]);
}
我的问题是它确实移动到了新屏幕并且它确实将屏幕旋转为横向,但几秒钟后,它又将它移回纵向。这是为什么 ?!我想不通!
编辑
我注意到,如果我不在菜单屏幕上调用forcePortrait(),板屏幕不会切换回纵向。但还是不知道为什么!
干杯!
【问题讨论】: