Solution
- Change your code to this:
void main() async {
WidgetsFlutterBinding.ensureInitialized();
///
/// Force the layout to Portrait mode
///
await SystemChrome.setPreferredOrientations(
[DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);
runApp(new MaterialApp(
debugShowCheckedModeBanner: false,
home: LoginScreen(),
));
}
- Open your Xcode project and go to Target -> Deployment Info ->
Require Full Screen
to true
. This will reflect in your ios/Runner/Info.plist to have the following value:
<key>UIRequiresFullScreen</key>
<true/>
Description
Well there are a couple of points to be addressed here:
- You forgot
WidgetsFlutterBinding.ensureInitialized()
. This IS important since you're "awaiting" on async main
method.
- According to
setPreferredOrientations
's documentation, there's a limitation regarding iPad multitasking:
This setting will only be respected on iPad if multitasking is
disabled.
To alleviate #2, from the docs:
Should you decide to opt out of multitasking you can do this by
setting "Requires full screen" to true in the Xcode Deployment Info.