Skip to content

SystemChrome.setPreferredOrientations does not force the device to the given orientations until the device is physically rotated #13238

@sroddy

Description

@sroddy

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    a: annoyanceRepeatedly frustrating issues with non-experimental functionalityc: API breakBackwards-incompatible API changescustomer: crowdAffects or could affect many people, though not necessarily a specific customer.engineflutter/engine related. See also e: labels.platform-iosiOS applications specifically

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions