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:

  1. The function queues up work to be done and returns an uncompleted Future object.
  2. Later, when the operation is finished, the Future object completes with a value or with an error.

优帆软件 —— 提供优质的软件外包服务

讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!