如何在颤动中将应用程序强制为人像模式

时间:2018-08-17 09:07:26

标签: flutter

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

  runApp(new MyApp());
}

3 个答案:

答案 0 :(得分:6)

将此代码放入MyApp()

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<link rel="stylesheet"
    href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
	<title></title>
</head>

<body>
	<div class="container">
	  <div class="views-exposed-widget">
	    <div contenteditable id="editable-text-name">
				Editable text here.
			</div>
	  </div>
	  <div class="views-submit-button">
	    <button id="save-button" type="button" onclick="alert('button clicked.')" class="btn btn-outline-dark">Save</button>
	  </div> 
	</div>
</body>

</html>

像下面这样:

  SystemChrome.setPreferredOrientations([
    DeviceOrientation.portraitUp,
    DeviceOrientation.portraitDown,
  ]);

答案 1 :(得分:1)

以下是适用于AndroidiOS的代码

Future main() async {
  await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
  runApp(new MyApp());
}

答案 2 :(得分:0)

以下代码对我有用。

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_app/splashScreen.dart';

    void main() {
      WidgetsFlutterBinding.ensureInitialized();
      SystemChrome.setPreferredOrientations([
        DeviceOrientation.portraitUp,
        DeviceOrientation.portraitDown,
      ]);

  runApp(MaterialApp(home: splashScreen(),));
}