I want to set my app's default orientation as landscape like when I open a game app such as clash of clans or mobile legend. How can I do that in flutter?
I want to set my app's default orientation as landscape like when I open a game app such as clash of clans or mobile legend. How can I do that in flutter?
Put this code in the MyApp()
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]);
Like below:
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]);
return new MaterialApp();
}
}
If you want the Portrait mode then check out this answer
You have to configure iOS and Android individually.
For iOS go to Xcode, select your project > General > Deployment Info > Device orientation and select only the landscape options.
For Android, add android:screenOrientation="landscape" to your <activity> tag.
Use SystemChrome.setPreferredOrientations to set the landscape or portrait mode when you start your main widget.
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
config();
return MaterialApp(
title: ...
);
}
void config() {
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight
]);
}
For Android, setPreferredOrientations works fine.
But for iOs, we have to use this solution (both phone and iPad): https://github.com/flutter/flutter/issues/13238#issuecomment-432981342