0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【第3回】Flutterで画面の向きを固定する方法

0
Posted at

画面向きを固定する方法(検索すれば山ほど回答は出ますが、自分の備忘録のため残しておきます)
※横向き固定
※ipadには対応しておりません

sample.dart
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
    SystemChrome.setPreferredOrientations([
    DeviceOrientation.landscapeLeft,
    // 横向き固定
  ]);
  runApp(MyApp());
}
'import package:flutter/services.dart';

こちらでパッケージを呼び出し

WidgetsFlutterBinding.ensureInitialized();
  await SystemChrome.setPreferredOrientations([
    DeviceOrientation.landscapeLeft,

runAPPの手前に上記を配置します。
そうすると横向きが固定されます。

landscapeRightでも横向き固定できるみたいですが、シミュレーター上ではあまり変化なし・・・?ここら辺はもう少し検証してみます。

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?