{"action":"created","issue":{"url":"https://api.github.com/repos/flutter/flutter/issues/13238","repository_url":"https://api.github.com/repos/flutter/flutter","labels_url":"https://api.github.com/repos/flutter/flutter/issues/13238/labels{/name}","comments_url":"https://api.github.com/repos/flutter/flutter/issues/13238/comments","events_url":"https://api.github.com/repos/flutter/flutter/issues/13238/events","html_url":"https://github.com/flutter/flutter/issues/13238","id":277597787,"number":13238,"title":"SystemChrome.setPreferredOrientations does not force the device to the given orientations until the device is physically rotated","user":{"login":"sroddy","id":729934,"avatar_url":"https://avatars2.githubusercontent.com/u/729934?v=4","gravatar_id":"","url":"https://api.github.com/users/sroddy","html_url":"https://github.com/sroddy","followers_url":"https://api.github.com/users/sroddy/followers","following_url":"https://api.github.com/users/sroddy/following{/other_user}","gists_url":"https://api.github.com/users/sroddy/gists{/gist_id}","starred_url":"https://api.github.com/users/sroddy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sroddy/subscriptions","organizations_url":"https://api.github.com/users/sroddy/orgs","repos_url":"https://api.github.com/users/sroddy/repos","events_url":"https://api.github.com/users/sroddy/events{/privacy}","received_events_url":"https://api.github.com/users/sroddy/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2017-11-29T01:27:48Z","updated_at":"2018-02-24T21:51:39Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"## Steps to Reproduce\r\n\r\nRunning on iOS 10/11\r\n\r\nStart an app in portrait mode and invoke:\r\n```\r\nSystemChrome.setPreferredOrientations([ DeviceOrientation.portraitUp ]);\r\n```\r\n\r\nthen invoke\r\n```\r\nSystemChrome.setPreferredOrientations([ DeviceOrientation.landscapeLeft ]);\r\n```\r\n\r\nNotice 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).\r\n\r\nThis 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.\r\n\r\nI workarounded the issue creating a small platform channel that invokes this code for switching to portrait right before the call to setPreferredOrientations:\r\n```\r\n[[UIDevice currentDevice] setValue:@(UIInterfaceOrientationPortrait) forKey:@\"orientation\"];\r\n```\r\nAnd the counterpart code for switching to landscape\r\n```\r\n[[UIDevice currentDevice] setValue:@(UIInterfaceOrientationLandscapeLeft) forKey:@\"orientation\"];\r\n```\r\n\r\nThis solved my issue.\r\nI 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.\r\n\r\nI 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.\r\n"},"comment":{"url":"https://api.github.com/repos/flutter/flutter/issues/comments/368263112","html_url":"https://github.com/flutter/flutter/issues/13238#issuecomment-368263112","issue_url":"https://api.github.com/repos/flutter/flutter/issues/13238","id":368263112,"user":{"login":"btastic","id":6894999,"avatar_url":"https://avatars3.githubusercontent.com/u/6894999?v=4","gravatar_id":"","url":"https://api.github.com/users/btastic","html_url":"https://github.com/btastic","followers_url":"https://api.github.com/users/btastic/followers","following_url":"https://api.github.com/users/btastic/following{/other_user}","gists_url":"https://api.github.com/users/btastic/gists{/gist_id}","starred_url":"https://api.github.com/users/btastic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/btastic/subscriptions","organizations_url":"https://api.github.com/users/btastic/orgs","repos_url":"https://api.github.com/users/btastic/repos","events_url":"https://api.github.com/users/btastic/events{/privacy}","received_events_url":"https://api.github.com/users/btastic/received_events","type":"User","site_admin":false},"created_at":"2018-02-24T21:51:39Z","updated_at":"2018-02-24T21:51:39Z","author_association":"NONE","body":"We just noticed that when the device was in landscape and then the flutter app is opened with \r\n\r\n```dart\r\nSystemChrome.setPreferredOrientations([\r\n  DeviceOrientation.portraitUp,\r\n]);\r\n```\r\n\r\nThe app will open in landscaped regardless of this setting."}}
{"actor":{"display_login":"btastic"}}