如何在颤动时强制应用程序进入纵向模式

Raj*_*008 8 flutter

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

  runApp(new MyApp());
}
Run Code Online (Sandbox Code Playgroud)

ibh*_*ana 7

将此代码放在MyApp()中

  SystemChrome.setPreferredOrientations([
    DeviceOrientation.portraitUp,
    DeviceOrientation.portraitDown,
  ]);
Run Code Online (Sandbox Code Playgroud)

如下所示:

import 'package:flutter/services.dart';

class MyApp extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      SystemChrome.setPreferredOrientations([
        DeviceOrientation.portraitUp,
        DeviceOrientation.portraitDown,
      ]);
      return new MaterialApp();
    }
  }
Run Code Online (Sandbox Code Playgroud)