Skip to content

The OrientationBuilder value and the MediaQuery's orientation value differ ? #177435

Closed

Description

@KikuchiTomo

Steps to reproduce

Hello! We deeply appreciate your ongoing development, contributions, and above all, maintenance of the excellent Flutter software.
We are using Flutter and find most aspects to be very comfortable and outstanding.
Recently, while implementing an application, we encountered the following case. We apologize for the inconvenience during your busy schedule, but we would be grateful if you could review this issue.

  1. Prepare a foldable Android device. (Here, we prepared an emulator for the Pixel 9 Pro Fold 36.1)
  2. When using OrientationBuilder with the foldable device unfolded, the results returned by MediaQuery will be inconsistent.

Expected results

We understand that OrientationBuilder depends on the orientation from the parent widget tree, but this creates inconsistencies with MediaQuery. We need to discuss either renaming the “OrientationBuilder” property in one of these mechanisms or building an entirely separate OrientationBuilder using MediaQuery values.

Actual results

Using OrientationBuilder with a folded device results in inconsistent MediaQuery outputs. While the results may be correct, I feel it would be better to either rename it or provide a dedicated widget like DeviceOrientationBuilder.

Code sample

OrientationBuilder
import 'package:flutter/material.dart';

class Orientation0 extends StatelessWidget {
  const Orientation0({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Flutter OrientationBuilder'),
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
      ),
      body: OrientationBuilder(
        builder: (context, orientation) {
          return Center(
            child: Text(
              orientation == Orientation.portrait ? 'portrait' : 'landscape',
              style: Theme.of(context).textTheme.headlineLarge,
            ),
          );
        },
      ),
    );
  }
}
MediaQuery.of(context).orientation
import 'package:flutter/material.dart';

class Orientation1 extends StatelessWidget {
  const Orientation1({super.key});

  @override
  Widget build(BuildContext context) {
    final orientation = MediaQuery.of(context).orientation;

    return Scaffold(
      appBar: AppBar(
        title: const Text('Flutter MediaQuery orientation'),
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
      ),
      body: Center(
        child: Text(
          orientation == Orientation.portrait ? 'portrait' : 'landscape',
          style: Theme.of(context).textTheme.headlineLarge,
        ),
      ),
    );
  }
}

Screenshots or Video

Screenshots / Video demonstration (Open)
OrientationBuilder MediaQuery.of(context).orientation
Image Image
Screenshots / Video demonstration (Fold)
OrientationBuilder MediaQuery.of(context).orientation
Image Image

Logs

Logs
Syncing files to device sdk gphone64 arm64...                       52ms

Flutter run key commands.
r Hot reload. 🔥🔥🔥
R Hot restart.
h List all available interactive commands.
d Detach (terminate "flutter run" but leave application running).
c Clear the screen
q Quit (terminate the application on the device).

A Dart VM Service on sdk gphone64 arm64 is available at: http://127.0.0.1:50638/KafzT7NIg7E=/
The Flutter DevTools debugger and profiler on sdk gphone64 arm64 is available at: http://127.0.0.1:9103?uri=http://127.0.0.1:50638/KafzT7NIg7E=/
I/Choreographer( 9098): Skipped 52 frames!  The application may be doing too much work on its main thread.
I/WindowExtensionsImpl( 9098): Initializing Window Extensions, vendor API level=9, activity embedding enabled=true
D/VRI[MainActivity]( 9098): WindowInsets changed: 2076x2152 statusBars:[0,136,0,0] navigationBars:[0,0,0,78] mandatorySystemGestures:[0,165,0,78]
D/WindowOnBackDispatcher( 9098): setTopOnBackInvokedCallback (unwrapped): android.view.ViewRootImpl$$ExternalSyntheticLambda12@8003047
I/rientation_demo( 9098): Compiler allocated 5274KB to compile void android.view.ViewRootImpl.performTraversals()
D/WindowLayoutComponentImpl( 9098): Register WindowLayoutInfoListener on Context=com.example.flutte_orientation_demo.MainActivity@4b46074, of which baseContext=android.app.ContextImpl@208595e
D/InsetsController( 9098): hide(ime())
I/ImeTracker( 9098): com.example.flutte_orientation_demo:a9cdc42e: onCancelled at PHASE_CLIENT_ALREADY_HIDDEN
W/WindowOnBackDispatcher( 9098): OnBackInvokedCallback is not enabled for the application.
W/WindowOnBackDispatcher( 9098): Set 'android:enableOnBackInvokedCallback="true"' in the application manifest.
D/ProfileInstaller( 9098): Installing profile for com.example.flutte_orientation_demo
W/WindowOnBackDispatcher( 9098): OnBackInvokedCallback is not enabled for the application.
W/WindowOnBackDispatcher( 9098): Set 'android:enableOnBackInvokedCallback="true"' in the application manifest.
W/WindowOnBackDispatcher( 9098): OnBackInvokedCallback is not enabled for the application.
W/WindowOnBackDispatcher( 9098): Set 'android:enableOnBackInvokedCallback="true"' in the application manifest.
D/ActivityThread( 9098): Package [com.android.vending] reported as REPLACED, but missing application info. Assuming REMOVED.
D/ActivityThread( 9098): Package [com.android.vending] reported as REPLACED, but missing application info. Assuming REMOVED.
W/rientation_demo( 9098): userfaultfd: MOVE ioctl seems unsupported: Connection timed out
W/WindowOnBackDispatcher( 9098): OnBackInvokedCallback is not enabled for the application.
W/WindowOnBackDispatcher( 9098): Set 'android:enableOnBackInvokedCallback="true"' in the application manifest.
D/VRI[MainActivity]( 9098): visibilityChanged oldVisibility=true newVisibility=false
D/VRI[MainActivity]( 9098): WindowInsets changed: statusBars:[0,152,0,0] navigationBars:null
D/ViewRootImpl( 9098): Skipping stats log for color mode
D/VRI[MainActivity]( 9098): WindowInsets changed: 1080x2424 navigationBars:[0,0,0,59] mandatorySystemGestures:[0,181,0,78]
D/InsetsController( 9098): hide(ime())
I/ImeTracker( 9098): com.example.flutte_orientation_demo:61dba0fa: onCancelled at PHASE_CLIENT_ALREADY_HIDDEN
W/WindowOnBackDispatcher( 9098): OnBackInvokedCallback is not enabled for the application.
W/WindowOnBackDispatcher( 9098): Set 'android:enableOnBackInvokedCallback="true"' in the application manifest.
W/WindowOnBackDispatcher( 9098): OnBackInvokedCallback is not enabled for the application.
W/WindowOnBackDispatcher( 9098): Set 'android:enableOnBackInvokedCallback="true"' in the application manifest.
D/ActivityThread( 9098): Package [com.google.android.webview] reported as REPLACED, but missing application info. Assuming REMOVED.
D/ActivityThread( 9098): Package [com.google.android.webview] reported as REPLACED, but missing application info. Assuming REMOVED.
D/ActivityThread( 9098): Package [com.google.android.as.oss] reported as REPLACED, but missing application info. Assuming REMOVED.
D/ActivityThread( 9098): Package [com.google.android.as.oss] reported as REPLACED, but missing application info. Assuming REMOVED.
D/ActivityThread( 9098): Package [com.google.android.apps.maps] reported as REPLACED, but missing application info. Assuming REMOVED.
D/ActivityThread( 9098): Package [com.google.android.apps.maps] reported as REPLACED, but missing application info. Assuming REMOVED.
D/ActivityThread( 9098): Package [com.google.android.apps.wellbeing] reported as REPLACED, but missing application info. Assuming REMOVED.
D/ActivityThread( 9098): Package [com.google.android.apps.wellbeing] reported as REPLACED, but missing application info. Assuming REMOVED.
D/ActivityThread( 9098): Package [com.google.android.apps.youtube.music] reported as REPLACED, but missing application info. Assuming REMOVED.
D/ActivityThread( 9098): Package [com.google.android.apps.youtube.music] reported as REPLACED, but missing application info. Assuming REMOVED.
D/ActivityThread( 9098): Package [com.google.android.apps.messaging] reported as REPLACED, but missing application info. Assuming REMOVED.
D/ActivityThread( 9098): Package [com.google.android.apps.messaging] reported as REPLACED, but missing application info. Assuming REMOVED.
D/ActivityThread( 9098): Package [com.google.android.googlequicksearchbox] reported as REPLACED, but missing application info. Assuming REMOVED.
D/ActivityThread( 9098): Package [com.google.android.googlequicksearchbox] reported as REPLACED, but missing application info. Assuming REMOVED.
D/ActivityThread( 9098): Package [com.google.android.contacts] reported as REPLACED, but missing application info. Assuming REMOVED.
D/ActivityThread( 9098): Package [com.google.android.contacts] reported as REPLACED, but missing application info. Assuming REMOVED.
D/ActivityThread( 9098): Package [com.google.android.apps.restore] reported as REPLACED, but missing application info. Assuming REMOVED.
D/ActivityThread( 9098): Package [com.google.android.apps.restore] reported as REPLACED, but missing application info. Assuming REMOVED.
D/ActivityThread( 9098): Package [com.google.android.partnersetup] reported as REPLACED, but missing application info. Assuming REMOVED.
D/ActivityThread( 9098): Package [com.google.android.partnersetup] reported as REPLACED, but missing application info. Assuming REMOVED.
D/ActivityThread( 9098): Package [com.google.android.tts] reported as REPLACED, but missing application info. Assuming REMOVED.
D/ActivityThread( 9098): Package [com.google.android.tts] reported as REPLACED, but missing application info. Assuming REMOVED.
D/ActivityThread( 9098): Package [com.google.android.deskclock] reported as REPLACED, but missing application info. Assuming REMOVED.
D/ActivityThread( 9098): Package [com.google.android.deskclock] reported as REPLACED, but missing application info. Assuming REMOVED.
D/ActivityThread( 9098): Package [com.google.android.apps.photos] reported as REPLACED, but missing application info. Assuming REMOVED.
D/ActivityThread( 9098): Package [com.google.android.apps.photos] reported as REPLACED, but missing application info. Assuming REMOVED.
D/ActivityThread( 9098): Package [com.google.android.accessibility.switchaccess] reported as REPLACED, but missing application info. Assuming REMOVED.
D/ActivityThread( 9098): Package [com.google.android.accessibility.switchaccess] reported as REPLACED, but missing application info. Assuming REMOVED.
D/ActivityThread( 9098): Package [com.google.android.apps.accessibility.voiceaccess] reported as REPLACED, but missing application info. Assuming REMOVED.
D/ActivityThread( 9098): Package [com.google.android.apps.accessibility.voiceaccess] reported as REPLACED, but missing application info. Assuming REMOVED.
D/ActivityThread( 9098): Package [com.google.android.dialer] reported as REPLACED, but missing application info. Assuming REMOVED.
D/ActivityThread( 9098): Package [com.google.android.dialer] reported as REPLACED, but missing application info. Assuming REMOVED.
D/ActivityThread( 9098): Package [com.google.android.apps.safetyhub] reported as REPLACED, but missing application info. Assuming REMOVED.
D/ActivityThread( 9098): Package [com.google.android.apps.safetyhub] reported as REPLACED, but missing application info. Assuming REMOVED.
D/ActivityThread( 9098): Package [com.google.android.inputmethod.latin] reported as REPLACED, but missing application info. Assuming REMOVED.
D/ActivityThread( 9098): Package [com.google.android.inputmethod.latin] reported as REPLACED, but missing application info. Assuming REMOVED.
D/ActivityThread( 9098): Package [com.google.android.youtube] reported as REPLACED, but missing application info. Assuming REMOVED.
D/ActivityThread( 9098): Package [com.google.android.youtube] reported as REPLACED, but missing application info. Assuming REMOVED.

Flutter Doctor output

Doctor output
❯ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.32.8, on macOS 15.7 24G222 darwin-arm64, locale ja-JP)
[✓] Android toolchain - develop for Android devices (Android SDK version 36.1.0)
[✓] Xcode - develop for iOS and macOS (Xcode 16.4)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2025.1)
[✓] VS Code (version 1.105.1)
[✓] Connected device (4 available)
[✓] Network resources

• No issues found!

Activity

  1. changed the title [-]The OrientationBuilder value and the MediaQuery's orientation value differ.[/-] [+]The OrientationBuilder value and the MediaQuery's orientation value differ[/+] on Oct 23, 2025
  2. changed the title [-]The OrientationBuilder value and the MediaQuery's orientation value differ[/-] [+]The OrientationBuilder value and the MediaQuery's orientation value differ ?[/+] on Oct 23, 2025
  3. added
    in triagePresently being triaged by the triage team
    on Oct 24, 2025
  4. huycozy commented on Oct 24, 2025

    @huycozy
    Member

    Thanks for the report. I'm also able to reproduce the issue on the latest Flutter stable and main channels. Tested on Pixel 9 Pro Fold (emulator).

    Flutter versions (stable and main)
    [✓] Flutter (Channel stable, 3.35.7, on macOS 26.0 25A354 darwin-arm64, locale en-US) [169ms]
        • Flutter version 3.35.7 on channel stable at /Users/huym4/Documents/WORKING/SDK/flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision adc9010625 (2 days ago), 2025-10-21 14:16:03 -0400
        • Engine revision 035316565a
        • Dart version 3.9.2
        • DevTools version 2.48.0
        • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-swift-package-manager, enable-lldb-debugging
    [!] Flutter (Channel main, 3.38.0-1.0.pre-228, on macOS 26.0 25A354 darwin-arm64, locale en-US) [3.3s]
        • Flutter version 3.38.0-1.0.pre-228 on channel main at /Users/huym4/Documents/WORKING/SDK/flutter_master
        ! Warning: `flutter` on your path resolves to /Users/huym4/Documents/WORKING/SDK/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/huym4/Documents/WORKING/SDK/flutter_master. Consider adding /Users/huym4/Documents/WORKING/SDK/flutter_master/bin to the front of your path.
        ! Warning: `dart` on your path resolves to /Users/huym4/Documents/WORKING/SDK/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/huym4/Documents/WORKING/SDK/flutter_master. Consider adding /Users/huym4/Documents/WORKING/SDK/flutter_master/bin to the front of your path.
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 78c9a49616 (3 hours ago), 2025-10-24 11:54:23 +0700
        • Engine revision 126de92e89
        • Dart version 3.11.0 (build 3.11.0-55.0.dev)
        • DevTools version 2.51.0
        • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-native-assets, omit-legacy-version-file, enable-lldb-debugging
        • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.

    I combined your 2 snippet codes into one example here:

    Sample code
    import 'package:flutter/material.dart';
    
    void main(List<String> args) {
      runApp(const MaterialApp(home: OrientationSelector()));
    }
    
    class OrientationSelector extends StatefulWidget {
      const OrientationSelector({super.key});
    
      @override
      State<OrientationSelector> createState() => _OrientationSelectorState();
    }
    
    class _OrientationSelectorState extends State<OrientationSelector> {
      bool _useOrientation0 = true;
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: const Text('Orientation Test'),
            backgroundColor: Theme.of(context).colorScheme.inversePrimary,
          ),
          body: Column(
            children: [
              Padding(
                padding: const EdgeInsets.all(16.0),
                child: Row(
                  children: [
                    Expanded(
                      child: ElevatedButton(
                        onPressed: () => setState(() => _useOrientation0 = true),
                        child: const Text('OrientationBuilder'),
                      ),
                    ),
                    const SizedBox(width: 12),
                    Expanded(
                      child: ElevatedButton(
                        onPressed: () => setState(() => _useOrientation0 = false),
                        child: const Text('MediaQuery'),
                      ),
                    ),
                  ],
                ),
              ),
              Expanded(
                child: _useOrientation0
                    ? const Orientation0()
                    : const Orientation1(),
              ),
            ],
          ),
        );
      }
    }
    
    class Orientation0 extends StatelessWidget {
      const Orientation0({super.key});
    
      @override
      Widget build(BuildContext context) {
        return OrientationBuilder(
          builder: (context, orientation) {
            return Center(
              child: Text(
                orientation == Orientation.portrait ? 'portrait' : 'landscape',
                style: Theme.of(context).textTheme.headlineLarge,
              ),
            );
          },
        );
      }
    }
    
    class Orientation1 extends StatelessWidget {
      const Orientation1({super.key});
    
      @override
      Widget build(BuildContext context) {
        final orientation = MediaQuery.of(context).orientation;
    
        return Center(
          child: Text(
            orientation == Orientation.portrait ? 'portrait' : 'landscape',
            style: Theme.of(context).textTheme.headlineLarge,
          ),
        );
      }
    }
    
    Demo
    untitled.webm
  5. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    and removed
    in triagePresently being triaged by the triage team
    on Oct 24, 2025
  6. KikuchiTomo commented on Oct 27, 2025

    @KikuchiTomo
    ContributorAuthor

    Thank you for responding!

    I understand you're likely focused on addressing other more critical issues, so I'm happy to wait for a discussion on this matter.

    If you could just indicate what kind of fix is needed, I can create the PR myself.

    (Actually, I've already created and submitted a PR ( #177437 ), but since it might not align with your team's approach, I'd appreciate discussing it here.)

  7. added
    P2Important issues not at the top of the work list
    on Oct 28, 2025
  8. KikuchiTomo commented on Nov 4, 2025

    @KikuchiTomo
    ContributorAuthor

    Hello, I'd be grateful if you could reply, even briefly. That's because if you could let me know which approach to take, I can make the necessary changes to the PR below anytime!

    #177437

  9. victorsanni commented on Nov 4, 2025

    @victorsanni
    Contributor

    Hi @KikuchiTomo, I left some comments on the PR, could you address them to continue the review iteration? So far the approach to add a new widget lgtm.

  10. KikuchiTomo commented on Nov 4, 2025

    @KikuchiTomo
    ContributorAuthor

    Thanks for your reply!
    I've changed it to a single file.
    I'd appreciate it if you could take a look whenever you have a moment.

  11. github-actions commented on Nov 24, 2025

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  12. locked as resolved and limited conversation to collaborators on Nov 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listfound in release: 3.35Found to occur in 3.35found in release: 3.38Found to occur in 3.38frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onteam-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions