-
Notifications
You must be signed in to change notification settings - Fork 26.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SystemChrome.setPreferredOrientations does not force the device to the given orientations until the device is physically rotated #13238
Comments
I am not sure why this is not working for you. From my reading of the documentation on Have you checked whether the supported interface orientations are present in the application's |
cc @cbracken |
I know they seem right. Unfortunately they don't work. https://stackoverflow.com/a/19125466
I've been fighting in the past with this issue in the last 1 year and half and so far the only consistent way I've found to deal with this is to check the real device orientation and force it to one of the supported ones if unsupported. |
@chinmaygarde @cbracken you can see here a basic example demonstrating the issue:
Notice that:
|
We just noticed that when the device was in landscape and then the flutter app is opened with SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
]); The app will open in landscaped regardless of this setting. |
In iPad, this method doesn't seem to be implemented. flutter doctor -v
|
+1 |
1 similar comment
+1 |
@miguelpruivo @crnaosa |
I am experiencing the same issue both with the iOS emulator (iPad Pro 9.7, iOS 12) and a physical device (iPad Air 2, iOS 11). I implemented the setPreferredOrientations method inside the main function, but there is no effect noticeable. This is a huge problem when developing with user interfaces which are designed to only work in either portrait or landscape mode, not both. Can we get an update on this? |
@sroddy Could you please share your solution? I'm facing the same issue and have no idea how to fix this on iOS. It seems that you fixed it. |
@albo1337 Not an ideal solution, but if you just want to get your whole app locked to a certain orientation, you can specify that inside the Info.plist file inside <key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string
<string>UIInterfaceOrientationLandscapeLeft</string
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string
<string>UIInterfaceOrientationPortraitUpsideDown</string
<string>UIInterfaceOrientationLandscapeLeft</string
<string>UIInterfaceOrientationLandscapeRight</string>
</array> Just remove the orientations that you do not support. Edit: Of course, this doesn't help if you need to lock specific views of your app, but might be helpful for anyone who stumbles upon this thread and wants their whole app locked ;) |
@lennartschoch the problem is, I need the landscape mode only for one screen and the portrait mode for every other screen... Your solution does not help me with my current problem, but thank you a lot for your help! |
@albo1337 that’s exactly what I need as well. |
@albo1337 I'm in the same case, I need the device in landscape for one screen and all the other in portrait. I have the same issue as you, you need to rotate the device for the UI to follow :( |
@albo1337 You basically need to create a custom platform channel and use it to force the desired orientation right after setting the preferred one. In Dart: SystemChrome.setPreferredOrientations([ DeviceOrientation.landscapeLeft ]);
_rotationChannel.invokeMethod('setLandscape'); in iOS code:
|
cc @chinmaygarde Does this new information bring anything to light on this issue? |
This sounds like it might be an easy fix? Maybe a starter bug for one of the new engine hackers @cbracken? The implementation of SystemChrome is here: |
Ha ha @eseidelGoogle ! Easy fix when you know where to do it 😆 I've searched on the source where to do this fix with no luck ^^ thanks for pointing that out ! |
Looks like someone even wrote a medium article about this and how to work around it. :/ |
CC @kriuz the author of said article. |
@eseidelGoogle I actually tried exactly that and couldn't get the orientation locked on an iPad Air 2 :/ |
It's hard for me to parse from this issue how much of this could be Flutter itself, vs if the plugins/APIs involved are just not calling the right iOS APIs to implement their desired functionality. Either are probably easy to fix? @xster might have a guess. |
@eseidelGoogle from my experience the only reliable way to force the orientation when the device itself is not rotated is setting it using key-value coding. It would be quite easy to provide a patch on the engine using this approach. Any other way unfortunately have proven to be unsuccessful. |
We believe this is fixed in |
@Hixie i don´t think it is fixed in dev as the merge was reverted. There´s a new merge request (flutter/engine#13170) but that´s not merged yet. |
I just tried the Dev channel and it is still not working as expected. |
@josh-ksr Sorry for the delay, it is merged again! |
Change is in master again as of 353721a |
I've removed the platform-android label, since this issue is very embedder-specific and the original issue, workarounds in comments, and fix are all iOS-specific. If people are running into a similar issue on Android, please file an issue and link it here from a comment to help others find it and add a thumbs-up reaction. Just so @elmariocarlos 's question does't get lost after this comment: @sroddy @btastic @lukasgit I'm closing this issue as fixed now that the patch has landed, but please let us know if you're still seeing this and we'll re-open. |
Issues still exists in both Andorid and iOS. Below is the Flutter Doctor report [✓] Flutter (Channel master, v1.10.16-pre.67, on Mac OS X 10.14.1 18B75, locale en-GB) [!] Android toolchain - develop for Android devices (Android SDK version 28.0.3) [!] Xcode - develop for iOS and macOS (Xcode 10.1) [✓] Chrome - develop for the web [✓] Android Studio (version 3.5) [✓] Connected device (3 available) ! Doctor found issues in 2 categories. |
I tried it, it is ok,
|
upgrade your flutter and retry |
Not working for me tried with |
Hello @lennartschoch, I think this will solve your issue , I tried it and it work on both platforms, return RotatedBox( |
Sounds like this is resolved based on other reports. @lennartschoch please let us know if @ztpr0035's suggestion doesn't work for you. |
Working fine on iPhone but still having problems on iPad, am I the only one?
UPDATE 13 January |
Oh man, I'm forced to use v1.9.x due to older phone compatability... Any workaround for that version? |
Is the only solution to this really to use a RotatedBox as @ztpr0035 mentioned? This doesn't properly change the screen's size like a native orientation change. I'm having lots of overflow errors trying to use that solution EDIT: Nevermind orientation is properly getting updated, my WillPopScope wasn't being triggered because I wasn't using maybePop(), duh.. |
Why this issue is not resolved but is marked as resolved |
The issue is closed but I think i can add this just incase. I am just learning flutter and in a lecture by Maximiliano of academind, he points out that for the issue at hand to work you need to add a |
then same |
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
Steps to Reproduce
Running on iOS 10/11
Start an app in portrait mode and invoke:
then invoke
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:
And the counterpart code for switching to landscape
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.
The text was updated successfully, but these errors were encountered: