-2

I have developed with flutter and i have a problem in Device Rotation.

for example, when an user clicked a button, it makes rotate device.(below code)

SystemChrome.setPreferredOrientations(
  _isPortrait
      ? [
          DeviceOrientation.landscapeRight,
        ]
      : [
          DeviceOrientation.portraitUp,
        ],
)

and end of rotation, i will change rotation landscape + portrait(to rotate user device directly)

so i used following code.

SystemChrome.setPreferredOrientations(
  _isPortrait
      ? [
          DeviceOrientation.landscapeRight,
        ]
      : [
          DeviceOrientation.portraitUp,
        ],
).then((value) {
  SystemChrome.setPreferredOrientations([]);
});

It is working under iOS16.

But in iOS16, it is not working.(after change rotation, it is rollback origin rotation with animation)

Who know this problem?

Thanks.

Gyeom
  • 1

3 Answers3

0

Previously apple was using UIDevice.current.setValue(value, forKey: "orientation") to set the orientation after iOS 16 the mentioned method got deprecated because of some bugs, instead of that they are recommending us to use windowScene.requestGeometryUpdate(.iOS(interfaceOrientations: orientation)) this method. for the further reference https://developer.apple.com/forums/thread/707735?answerId=726322022#726322022

Jok3r
  • 454
  • 3
  • 9
0

Here how I solved the issue:

Flutter documentation says (https://api.flutter.dev/flutter/services/SystemChrome/setPreferredOrientations.html):

"Limitations This setting will only be respected on iPad if multitasking is disabled. You can decide to opt out of multitasking on iPad, then setPreferredOrientations will work but your app will not support Slide Over and Split View multitasking anymore. Should you decide to opt out of multitasking you can do this by setting "Requires full screen" to true in the Xcode Deployment Info."

So I added in info.plist:

<key>UIRequiresFullScreen</key>

<true/>

0

Currently, I would choose to use the plugin https://pub.dev/packages/auto_orientation for handling screen rotation, while utilizing SystemChrome.setPreferredOrientations for configuring the supported screen orientations on specific pages. I noticed that the issue doesn't arise when I don't attempt to change the supported screen orientations for a page. It might be beneficial to introduce an additional method for configuring screen rotation, separate from setting the supported page orientations.

see https://github.com/flutter/flutter/issues/132546

yuhui
  • 1
  • 1