Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter: How to avoid change orientation?

I have a final user design with landscape orientation. User doesn't want/need portrait and it is needed to avoid automatic orientation change on iOS/Android. How can I achieve that?

like image 436
abnerh69 Avatar asked Nov 20 '17 13:11

abnerh69


People also ask

How do you turn off auto rotate on Flutter app?

Create SystemChrome. setPreferredOrientations() method to disable Screen rotation in Widget build area of MyApp class just before the return part.

How do I change the default orientation in Flutter?

In Flutter we have SystemChrome. setPreferredOrientation() (see documentation) to define preferred orientation. Exactly this method you can find in all those articles about setup orientation in Flutter.


1 Answers

SystemChrome is what you want

You can do something like in main.dart (don't forget import 'package:flutter/services.dart')

SystemChrome.setPreferredOrientations([
    DeviceOrientation.landscapeRight,
    DeviceOrientation.landscapeLeft,
]);

Unfortunately, when I do this in my application, the orientation will always be landscapeRight.

To lock the orientation for iOS you need to change the settings for the XCode project (use command 'open ios/Runner.xcworkspace' in terminal to open it)

like image 96
Rémi Rousselet Avatar answered Sep 24 '22 01:09

Rémi Rousselet