I would like to prevent my application from changing its orientation and force the layout to stick to "portrait".
In the main.dart, I put:
void main(){
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown
]);
runApp(new MyApp());
}
but when I use the Android Simulator rotate buttons, the layout "follows" the new device orientation…
How could I solve this?
Thanks
Best Answer
Import
package:flutter/services.dart
, thenPut the
SystemChrome.setPreferredOrientations
inside theWidget build()
method.Example:
Update
This solution mightn't work for some IOS devices as mentioned in the updated flutter documentation on Oct 2019.
They Advise to fixed the orientation by setting UISupportedInterfaceOrientations in Info.plist like this
For more information https://github.com/flutter/flutter/issues/27235#issuecomment-508995063