Flutter 如何在Flatter中将我的应用程序设置为横向模式?
我想在打开游戏应用程序(如clash of clans或mobile legend)时,将应用程序的默认方向设置为横向。我如何在Flatter中做到这一点?您必须分别配置iOS和Android 对于iOS,请转到Xcode,选择您的项目>常规>部署信息>设备方向,然后仅选择横向选项Flutter 如何在Flatter中将我的应用程序设置为横向模式?,flutter,flutter-layout,Flutter,Flutter Layout,我想在打开游戏应用程序(如clash of clans或mobile legend)时,将应用程序的默认方向设置为横向。我如何在Flatter中做到这一点?您必须分别配置iOS和Android 对于iOS,请转到Xcode,选择您的项目>常规>部署信息>设备方向,然后仅选择横向选项 对于Android,将Android:screenOrientation=“scape”添加到您的标签。使用SystemChrome.setPreferredOrientations在启动主小部件时设置横向或纵向模式
对于Android,将
Android:screenOrientation=“scape”
添加到您的
标签。使用SystemChrome.setPreferredOrientations
在启动主小部件时设置横向或纵向模式
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
config();
return MaterialApp(
title: ...
);
}
void config() {
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight
]);
}
将此代码放入MyApp()中
如下图所示:
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]);
return new MaterialApp();
}
}
如果您想要纵向模式,请查看Android版的此功能,setPreferredOrientations可以正常工作
但对于iOs,我们必须使用此解决方案(包括手机和iPad):欢迎使用。你能更详细地描述一下你的问题吗?例如,通过添加描述问题的代码、命令或屏幕截图。还请查看帮助中心,尤其是和。谢谢。我发现我需要这样做,@diegoveloper建议强制一个颤振应用程序立即启动并只停留在横向模式。这对我很有效。确保你正在调用
config()
方法,最好是在你的主方法中。通过使用上述解决方案,我认为第一次应用程序将以纵向模式打开,然后在更改方向纵向后保持横向。我的意思是你必须改变第一次肖像景观应用程序将不会打开与景观。
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]);
return new MaterialApp();
}
}