跪拜 Guibai
← All articles
Flutter · Android · iOS

Locking Flutter Screen Orientation in main() Silently Kills iPad Multitasking

By GitLqr ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

The bug survives testing because simulators and iPhones mask it completely; only a physical iPad reveals the missing multitasking support. A single convenience line in `main()` can generate negative App Store reviews for months before anyone connects the dots.

Summary

Locking screen orientation globally in Flutter's `main()` function works perfectly on iPhones but silently disqualifies an iPad app from multitasking. Apple requires apps to support all interface orientations to participate in Split View and Slide Over; a runtime orientation lock signals the app cannot reflow its layout, so iPadOS excludes it entirely. The failure produces no crash, no log, and no visible defect until a user tries to use the app side-by-side with another.

The fix is to move orientation locks to individual pages via `initState` and release them in `dispose` by passing an empty list to `setPreferredOrientations`. For apps that genuinely never support landscape, declare the restriction in `Info.plist` or `AndroidManifest.xml` instead of enforcing it at runtime. This keeps the system's understanding of the app's capabilities accurate.

Takeaways
`SystemChrome.setPreferredOrientations` called in `main()` causes iPadOS to exclude the app from Split View and Slide Over.
The failure is silent: no crash, no error, and the app otherwise runs normally on iPad.
Apple requires all interface orientations to be supported for an app to qualify for iPad multitasking.
Move orientation locks to per-page `initState` and release them in `dispose` with an empty list.
For apps that never support landscape, declare the restriction natively in `Info.plist` or `AndroidManifest.xml` rather than locking at runtime.
Conclusions

A runtime API that behaves identically on two Apple platforms produces opposite system-level consequences, and the platform that breaks gives no feedback. This class of bug — silent capability removal — is especially dangerous in cross-platform frameworks where developers test primarily on one device family.

The recommended per-page lock-and-release pattern treats orientation as a temporary UI constraint rather than a permanent app property, which aligns with how iPadOS actually evaluates multitasking eligibility.

Concepts & terms
Slide Over
An iPad multitasking mode where a second app floats in a narrow panel over the primary app, allowing quick interactions without leaving the current context.
Split View
An iPad multitasking mode that places two apps side-by-side in resizable panes, requiring both apps to support dynamic layout changes across all orientations.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗