Skip to content

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

@KikuchiTomo

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!

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