Ash*_*iya 28
强行启用
导入包:import 'package:flutter/services.dart';在main.dart文件中
1.横向模式:
// Set landscape orientation
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]);
Run Code Online (Sandbox Code Playgroud)
2. 人像模式:
// Set portrait orientation
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitDown,
DeviceOrientation.portraitUp,
]);
Run Code Online (Sandbox Code Playgroud)
小智 9
import 'package:flutter/services.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeLeft])
.then((_) {
runApp(new MyApp());
});
}
Run Code Online (Sandbox Code Playgroud)
小智 5
SystemChrome.setPreferredOrientations适用于应用程序的 Flutter 部分,但它不是完整的解决方案。因为当您启动应用程序时 - Flutter 尚未创建。因此,您还应该在本机部件中设置方向。
这里有详细说明的文章https://medium.com/@greymag/flutter-orientation-lock-portrait-only-c98910ebd769
| 归档时间: |
|
| 查看次数: |
15895 次 |
| 最近记录: |