I want to show a single page in my Flutter application in landscape mode. Every other screen should be shown in portrait mode.
I found this code snippet:
In my main.dart
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]).then((_) {
runApp(new IHGApp());
});
This starts the app in portrait mode. So I have the screen I want to show in landscape mode and this is the code I used there:
@override
void initState() {
super.initState();
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeRight,
DeviceOrientation.landscapeLeft,
]);
}
@override
void dispose() {
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
super.dispose();
}
This works on Android.
On iOS it seems there is no way to force landscape mode for a single page.
https://github.com/flutter/flutter/issues/13238
On this article I found the issue for this problem. sroddy mentioned how to fix the problem.
"I workarounded the issue creating a small platform channel that invokes this code for switching to portrait right before the call to setPreferredOrientations:"
[[UIDevice currentDevice] setValue:@(UIInterfaceOrientationPortrait) forKey:@"orientation"];
And the counterpart code for switching to landscape
[[UIDevice currentDevice] setValue:@(UIInterfaceOrientationLandscapeLeft) forKey:@"orientation"];
How can I implement this in my app?