Flutter 禁止横屏 landscape
需要在 main.dart 中引入:
import 'package:flutter/services.dart';
// wait until `setPreferredOrientations` is done and start the app
// this works.
void main() {
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp])
.then((_) {
runApp(new MyApp());
});
}
setPreferredOrientations 会异步返回一个 Future 对象,我们需要等异步调用完成后再启动 App
A future is a Future object, which represents an asynchronous operation that produces a result of type T. If the result isn’t a usable value, then the future’s type is Future. When a function that returns a future is invoked, two things happen:
- The function queues up work to be done and returns an uncompleted Future object.
- Later, when the operation is finished, the Future object completes with a value or with an error.