在主菜单屏幕上,我调用
我的问题是,它确实可以切换到新屏幕并将屏幕旋转为横向,但几秒钟后,它会自动恢复为纵向。这是为什么?我无法弄清楚!
编辑
我注意到,如果我在菜单屏幕上不调用
干杯!
forcePortrait()
函数,该函数的作用是:static Future forcePortrait() async {
await SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
}
然后...我将在主菜单屏幕内部调用以下内容:
Navigator.push(context, MaterialPageRoute(builder: (context) => ScreenBoard()));
在“Board”屏幕中,我将如下调用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()方法
static void forceLandscape() async {
await SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]);
}
我的问题是,它确实可以切换到新屏幕并将屏幕旋转为横向,但几秒钟后,它会自动恢复为纵向。这是为什么?我无法弄清楚!
编辑
我注意到,如果我在菜单屏幕上不调用
forcePortrait()
,则游戏板屏幕不会切换回纵向。但我仍然无法找出原因!干杯!