我想阻止我的应用程序改变其方向并强制布局坚持“纵向”。
在 main.dart 中,我放置了:
void main(){
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown
]);
runApp(new MyApp());
}
但是当我使用 Android 模拟器旋转按钮时,布局“遵循”新的设备方向......
我该如何解决这个问题?
Thanks
Import package:flutter/services.dart
, then
Put the SystemChrome.setPreferredOrientations
在 - 的里面Widget build()
method.
Example:
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
return new MaterialApp(...);
}
}
Update
正如 2019 年 10 月更新的 flutter 文档中所述,此解决方案可能不适用于某些 IOS 设备。
他们建议通过在 Info.plist 中设置 UISupportedInterfaceOrientations 来固定方向,如下所示
<array>
<string>UIInterfaceOrientationPortrait</string>
</array>
了解更多信息https://github.com/flutter/flutter/issues/27235#issuecomment-508995063 https://github.com/flutter/flutter/issues/27235#issuecomment-508995063
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)