-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Description
Steps to Reproduce
Running on iOS 10/11
Start an app in portrait mode and invoke:
SystemChrome.setPreferredOrientations([ DeviceOrientation.portraitUp ]);then invoke
SystemChrome.setPreferredOrientations([ DeviceOrientation.landscapeLeft ]);Notice that neither the device neither the simulator automatically rotate until you physically rotate the device (and does not rotate at all if the device rotation trigger is locked).
This happens because calling +[UIViewController attemptRotationToDeviceOrientation] here https://github.com/flutter/engine/blob/master/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm#L703 is unfortunately not enough.
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"];This solved my issue.
I think the current behaviour under iOS is bugged, moreover because my expected behaviour is what is currently happening on the Android counterpart without the need of any workaroud.
I know that the proposed way to fix it looks bad (using key-value coding on a read-only property), but if you search around the Internet, it seems to be the most reliable (and possibly only) way to handle this thing when you have just one view / view controller.