在颤动中强制纵向视图

Sam*_*mer 1 dart flutter

我尝试使用我在该网站的线程上找到的代码,但发生的只是我的应用程序加载白屏。有没有更好的方法在颤动中强制纵向视图?设置起来似乎很简单。

void main() async {
  ///
  /// Force the layout to Portrait mode
  ///
  await SystemChrome.setPreferredOrientations(
      [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);

  runApp(new MaterialApp(
    debugShowCheckedModeBanner: false,
    home: LoginScreen(),
  ));
}
Run Code Online (Sandbox Code Playgroud)

Kha*_*tha 5

将您的代码更改为

void main() {
 WidgetsFlutterBinding.ensureInitialized();
 SystemChrome.setPreferredOrientations(
 [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown])
 .then((_) => runApp(new MaterialApp(
         debugShowCheckedModeBanner: false,
         home: LoginScreen(), 
      )));
}
Run Code Online (Sandbox Code Playgroud)

`