【Flutter】画面の向きを縦や横に固定する
縦固定するなら main.dart
にこのように書く。
void main(){
WidgetsFlutterBinding.ensureInitialized();
//向き指定
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,//縦固定
]);
//runApp
runApp(MyApp());
}
WidgetsFlutterBinding.ensureInitialized()
を最初に書かないと起動時に以下のようなエラーメッセージが出てしまうので、書いておきましょう。
FlutterError (ServicesBinding.defaultBinaryMessenger was accessed before the binding was initialized.
If you're running an application and need to access the binary messenger beforerunApp()
has been called (for example, during plugin initialization), then you need to explicitly call theWidgetsFlutterBinding.ensureInitialized()
first.
If you're running a test, you can call theTestWidgetsFlutterBinding.ensureInitialized()
as the first line in your test'smain()
method to initialize the binding.)
参考: https://github.com/flutter/flutter/issues/40253
DeviceOrientation
以下の4パターンの指定ができます。
enum DeviceOrientation {
portraitUp,
landscapeLeft,
portraitDown,
landscapeRight,
}
Author And Source
この問題について(【Flutter】画面の向きを縦や横に固定する), 我々は、より多くの情報をここで見つけました https://qiita.com/osamu1203/items/6172df89f5270060a44d著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .