Reputation: 654
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?
Upvotes: 8
Views: 8995
Reputation: 2114
Add this line of code in your main.dart file
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
Upvotes: 3
Reputation: 277037
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)
Upvotes: 18
Reputation: 2874
void main() {
SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeLeft])
.then((_) {
runApp(new MyApp());
});
}
SystemChrome.setPreferredOrientations
returns a Future. Wait until that’s done and then we can start our app.
Upvotes: 15