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 mai
This solution has worked for me on two different projects for Android. Can't guarantee it will work for iOS too. I've read all the previous answers and I think the best and simplest solution is to do it like this:
This way you avoid all the "await"s, "async"s and "then"s that might mess around with your code
/// this is in main.dart
main(){
WidgetsFlutterBinding.ensureInitialized();
runApp(
MaterialApp(
initialRoute: '/root',
routes: {
'/root': (context) => MyApp(),
},
title: "Your App Title",
),
);
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
/// ENFORCE DEVICE ORIENTATION PORTRAIT ONLY
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown
]);
/// RUN THE APP
return MaterialApp(
home: HomeScreen(),
);
}
}
I think this answer's update is your best bet for iOS.
!! DISCLAIMER !! I did a little bit of research and apparently, the documentation here specifically says:
setPreferredOrientations method Limitations:
"This setting will only be respected on iPad if multitasking is disabled."
Here is how you can disable multitasking (AKA turn on "Requires Full Screen" option) from XCode
You might also try this one out. I haven't tried it personally, since I don't have an iPad or XCode on my PC, but it's worth a shot