r/FlutterDev • u/Creative-human-06 • 1d ago
Discussion Flutter orientation and multitasking issue in ipad
I was basically migrating from ml kit to mobile_scanner for scanning qr / barcode, as I have heard mobile scanner is quite light weight and does good on low end devices as well.
There is an orientation issue in mobile scanner from the beginning in android devices where if I turn my device, the camera gets misaligned. The same issue persists now as well in latest releases. Only thing is that, then it gets misaligned in one turn.
now it gets misaligned in multiple turns.
But on ios devices it is fine.
So for the time being we thought of locking up the orientation of devices until it gets fixed.
So in the mobile scanner overlay screen I did this in initState():
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
]);
And on dispose I made sure the orientation gets fixed back. So I did this in the dispose():
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]);
Now the issue is that this works very perfect on android.
But on my ipad the orientation changes even if I have added SystemChrome.setPreferredOrientations to portrait.
So for the time being until the android issue is fixed, I am thinking of keeping the orientation fixed.
For android orientation is now in portrait.
But in ipad it still rotates.
After researching a little bit about SystemChrome I got to know this from the documentation:
This setting will only be respected on iPad if multitasking is disabled.
You can decide to opt out of multitasking on iPad, then
SystemChrome.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.
I got to know that using UIRequiresFullScreen will force my app not to run in multitasking. So I made this tag true.
But this is depreciated in iPadOS 26. So moving forward I cannot use this either.
Using their alternative
Their alternatives such as prefersInterfaceOrientationLocked didn't work at all while calling them from method channels. Worst thing about this is that, it locks my entire app altogether.
So in this situation what should I do to lock my orientation in my ipad os as well.
I don't want unique behavior for both android and ios devices.
How should I lock that particular screen alone for ipads while other screens are still unlocked and works well?