Orientation for single page broken on iOS 16

This issue has been tracked since 2023-03-17.

The issue happens when the app is portrait orientation only and one page allows all orientations.
https://user-images.githubusercontent.com/2540606/225973323-8b08aa07-71b4-4d35-a584-d830e7ba7611.mov

Steps to Reproduce

  1. Clone example modified form_app
  2. Run on an iOS device (may only happen on iOS 16)
  3. Hold the phone in portrait orientation
  4. Open the form_widget page
  5. Rotate form to landscape orientation
  6. Close the form widget page - notice the app will be forced to portrait
  7. Reopen the form widget page and try to rotate to landscape

Expected results: The app rotates to landscape
Actual results: The app is stuck in portrait on all pages until fully closed and reopened

Code sample [form_app](https://github.com/Aldaniee/samples/tree/main/form_app)
Logs
form_app % flutter analyze  
Analyzing form_app...                                                   
No issues found! (ran in 2.0s)
form_app % flutter doctor -v
[!] Flutter (Channel stable, 3.7.4, on macOS 13.2.1 22D68 darwin-x64, locale en-US)
    • Flutter version 3.7.4 on channel stable at /Users/aidanlee/Developer/flutter
    ! Warning: `dart` on your path resolves to /usr/local/Cellar/dart/2.19.0/libexec/bin/dart, which is not inside your current Flutter SDK checkout at
      /Users/aidanlee/Developer/flutter. Consider adding /Users/aidanlee/Developer/flutter/bin to the front of your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision b4bce91dd0 (4 weeks ago), 2023-02-21 09:50:50 +0800
    • Engine revision 248290d6d5
    • Dart version 2.19.2
    • DevTools version 2.20.1
    • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    • Android SDK at /Users/aidanlee/Library/Android/sdk
    • Platform android-33, build-tools 33.0.1
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14C18
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)

[!] Android Studio (version 2022.1)
    • Android Studio at /Users/aidanlee/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/221.6008.13.2211.9514443/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    ✗ Unable to find bundled Java version.
    • Try updating or re-installing Android Studio.

[!] Android Studio (version 2022.1)
    • Android Studio at /Users/aidanlee/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/221.6008.13.2211.9477386/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    ✗ Unable to find bundled Java version.
    • Try updating or re-installing Android Studio.

[✓] IntelliJ IDEA Ultimate Edition (version 2022.3.2)
    • IntelliJ at /Users/aidanlee/Applications/JetBrains Toolbox/IntelliJ IDEA Ultimate.app
    • Flutter plugin version 72.1.4
    • Dart plugin version 223.8888

[✓] IntelliJ IDEA Ultimate Edition (version 2022.3.2)
    • IntelliJ at /Users/aidanlee/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/223.8617.56/IntelliJ IDEA.app
    • Flutter plugin version 71.3.6
    • Dart plugin version 223.8617.8

[✓] VS Code (version 1.67.2)
    • VS Code at /Users/aidanlee/Downloads/Visual Studio Code 2.app/Contents
    • Flutter extension version 3.58.0

[✓] VS Code (version 1.48.2)
    • VS Code at /Users/aidanlee/Downloads/Visual Studio Code.app/Contents
    • Flutter extension version 3.58.0

[✓] Connected device (3 available)
    • Aidan’s iPhone (mobile) • 00008101-001C54A01A32001E • ios            • iOS 16.3.1 20D67
    • macOS (desktop)         • macos                     • darwin-x64     • macOS 13.2.1 22D68 darwin-x64
    • Chrome (web)            • chrome                    • web-javascript • Google Chrome 111.0.5563.64

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 3 categories.
Aldaniee wrote this answer on 2023-03-17

I committed a hack that makes the example slightly better. If you use setPreferredOrientations twice with only portraitDown first the app is not stuck in portrait orientation forever, but instead can be "reset".

The changes:

  Future<void> _setOrientationToPortrait() async {
    await SystemChrome.setPreferredOrientations(<DeviceOrientation>[
      DeviceOrientation.portraitDown,
    ]);
    await SystemChrome.setPreferredOrientations(<DeviceOrientation>[
      DeviceOrientation.portraitDown,
      DeviceOrientation.portraitUp,
    ]);
  }

Steps to "Reset":

  1. Do all the above steps to get stuck in portrait mode on form widget page
  2. Physically rotate the phone back to portrait
  3. Close the form widget page
  4. Reopen the form widget page (still in portrait)
  5. You are able to rotate to landscape

This is the best setup I have found so far as a hacky solution but there may be a better one.

More Details About Repo
Owner Name flutter
Repo Name flutter
Full Name flutter/flutter
Language Dart
Created Date 2015-03-06
Updated Date 2023-03-30
Star Count 151602
Watcher Count 3555
Fork Count 25000
Issue Count 11498

YOU MAY BE INTERESTED

Issue Title Created Date Updated Date