Visitar URL original
[Cupertino] MediaQuery.of(context) returns Size(0,0) inside CupertinoNavigationBar trailing since Flutter 3.35 · Issue #174771 · flutter/flutter · GitHub
Skip to content

[Cupertino] MediaQuery.of(context) returns Size(0,0) inside CupertinoNavigationBar trailing since Flutter 3.35 #174771

Closed

Description

@flowhorn

Since upgrading to Flutter 3.35, MediaQuery.of(context) (or MediaQuery.sizeOf(context)) inside the trailing (or leading) builder of a CupertinoNavigationBar returns Size(0.0, 0.0).

This behavior did not occur in earlier Flutter versions and does not occur with Material widgets. It looks like the CupertinoNavigationBar now wraps its action widgets with its own MediaQuery that overrides the inherited size.

This breaks cases where responsive logic or layout decisions are made inside the navigation bar action buttons.

It seems to be related to the CupertinoNavigationBar and MediaQuery behaviour.

Steps to reproduce

  1. Create a minimal CupertinoApp with a CupertinoPageScaffold and a CupertinoNavigationBar.
  2. Place a widget in the trailing slot that calls MediaQuery.of(context).size.
  3. Observe the reported size.

Expected results

Both MediaQuery Outputs should be the same as prior to flutter 3.35

Actual results

rootMediaQuery.size: Size(1200.0, 738.0)
trailingMediaQuery.size: Size(0.0, 0.0)

Code sample

Code sample
import 'package:flutter/cupertino.dart';

void main() {
  runApp(
    CupertinoApp(
      title: 'Cupertino PageScaffold MediaQuery Bug',
      debugShowCheckedModeBanner: false,
      home: _Home(),
    ),
  );
}

class _Home extends StatelessWidget {
  const _Home();

  @override
  Widget build(BuildContext context) {
    final rootMediaQuery = MediaQuery.of(context);
    print('rootMediaQuery.size: ${rootMediaQuery.size}');

    return CupertinoPageScaffold(
      navigationBar: CupertinoNavigationBar(
        trailing: Builder(
          builder: (context) {
            return CupertinoButton.tinted(
              onPressed: () {
                final trailingMediaQuery = MediaQuery.of(context);
                print('trailingMediaQuery.size: ${trailingMediaQuery.size}');
              },
              child: const Icon(CupertinoIcons.info_circle),
            );
          },
        ),
      ),
      child: const Center(
        child: Text('Check logs for MediaQuery sizes'),
      ),
    );
  }
}

Screenshots or Video

No response

Logs

Logs
rootMediaQuery.size: Size(1200.0, 738.0)
trailingMediaQuery.size: Size(0.0, 0.0)

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.35.2, on macOS 15.6.1 24G90 darwin-arm64, locale ***) [285ms]
    • Flutter version 3.35.2 on channel stable at ***
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 05db968908 (6 days ago), 2025-08-25 10:21:35 -0700
    • Engine revision a8bfdfc394
    • Dart version 3.9.0
    • 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

Activity

  1. realmeylisdev commented on Aug 31, 2025

    @realmeylisdev
    Contributor

    The Problem

    In packages/flutter/lib/src/cupertino/nav_bar.dart at lines 2147-2152, the trailing widget is wrapped with a MediaQuery that only provides textScaler data:

    child: MediaQuery(
    data: MediaQueryData(
    textScaler: MediaQuery.textScalerOf(context).clamp(minScaleFactor: 1.0, maxScaleFactor: _kMaxScaleFactor),
    ),
    child: IconTheme.merge(data: const IconThemeData(size: 32.0), child: userTrailing),
    ),

    The same pattern occurs for:

    • Leading widget (lines 2012-2017)
    • Middle widget (lines 2121-2126)
    • Back chevron (lines 2042-2047)
    • Back label (lines 2074-2079)

    Why This Causes Size(0,0)

    When you create a MediaQueryData with only specific properties (like textScaler), all other properties default to their initial values. For size, this defaults to Size.zero (0,0).

    Impact Assessment

    This is a regression introduced in Flutter 3.35 that:

    • Breaks responsive logic in navigation bar components
    • Only affects Cupertino widgets (Material widgets work correctly)
    • Affects leading, trailing, middle, and back button widgets

    Recommended Triage Classification

    • Labels: c: regression, f: cupertino, a: accessibility, team-design
    • Priority: P1 (high priority regression affecting responsive UI)
    • Has reproducible steps: ✅ Clear reproduction case provided
    • Root cause identified: ✅ Specific code location pinpointed

    Fix Approach

    The MediaQueryData constructor calls should use copyWith() to preserve inherited values:

    data: MediaQuery.of(context).copyWith(
    textScaler: MediaQuery.textScalerOf(context).clamp(...),
    ),

    This preserves the original size, padding, and other MediaQuery properties while only modifying the text scaling behavior.

  2. danagbemava-nc commented on Sep 1, 2025

    @danagbemava-nc
    Member

    Reproducible using the code sample provided above. I can confirm that this works as expected on stable 3.32.8 but not on stable 3.35.2 or the latest master.

    Labeling for further investigation

    flutter run (stable 3.32.8)
    Launching lib/main.dart on Nexus (wireless) in debug mode...
    Automatically signing iOS for device deployment using specified development team in Xcode project: X8NNQ9CYL2
    Running Xcode build...                                                  
     └─Compiling, linking and signing...                        13.7s
    Xcode build done.                                           25.4s
    You may be prompted to give access to control Xcode. Flutter uses Xcode to run your app. If access is not allowed, you can change this
    through your Settings > Privacy & Security > Automation.
    Installing and launching...                                       111.2s
    Syncing files to device Nexus (wireless)...                        425ms
    
    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 Nexus (wireless) is available at: http://127.0.0.1:56623/pX6Yb7oTcvw=/
    The Flutter DevTools debugger and profiler on Nexus (wireless) is available at:
    http://127.0.0.1:9100?uri=http://127.0.0.1:56623/pX6Yb7oTcvw=/
    flutter: trailingMediaQuery.size: Size(375.0, 812.0)
    flutter: trailingMediaQuery.size: Size(375.0, 812.0)
    flutter: trailingMediaQuery.size: Size(375.0, 812.0)
    flutter: trailingMediaQuery.size: Size(375.0, 812.0)
    flutter: trailingMediaQuery.size: Size(375.0, 812.0)
    flutter: trailingMediaQuery.size: Size(375.0, 812.0)
    flutter: trailingMediaQuery.size: Size(375.0, 812.0)
    flutter: trailingMediaQuery.size: Size(375.0, 812.0)
    
    Application finished.
    flutter run (stable 3.35+)
    Launching lib/main.dart on Nexus (wireless) in debug mode...
    Automatically signing iOS for device deployment using specified development team in Xcode project: X8NNQ9CYL2
    Running Xcode build...                                                  
    Xcode build done.                                           20.0s
    [Scene] CLIENT OF UIKIT REQUIRES UPDATE: This process does not adopt UIScene lifecycle. This will become an assert in a future version.
    flutter: rootMediaQuery.size: Size(375.0, 812.0)
    Installing and launching...                                        46.0s
    [] App is being debugged, do not track this hang
    [] Hang detected: 4.23s (debugger attached, not reporting)
    [] App is being debugged, do not track this hang
    [] Hang detected: 13.44s (debugger attached, not reporting)
    flutter: rootMediaQuery.size: Size(375.0, 812.0)
    Syncing files to device Nexus (wireless)...                        281ms
    
    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 Nexus (wireless) is available at: http://127.0.0.1:58330/hGfiseq26YQ=/
    [] App is being debugged, do not track this hang
    [] Hang detected: 72.37s (debugger attached, not reporting)
    The Flutter DevTools debugger and profiler on Nexus (wireless) is available at:
    http://127.0.0.1:9100?uri=http://127.0.0.1:58330/hGfiseq26YQ=/
    [] App is being debugged, do not track this hang
    [] Hang detected: 32.72s (debugger attached, not reporting)
    [] App is being debugged, do not track this hang
    [] Hang detected: 2.30s (debugger attached, not reporting)
    [] App is being debugged, do not track this hang
    [] Hang detected: 5.02s (debugger attached, not reporting)
    flutter: trailingMediaQuery.size: Size(0.0, 0.0)
    flutter: trailingMediaQuery.size: Size(0.0, 0.0)
    flutter: trailingMediaQuery.size: Size(0.0, 0.0)
    
    Application finished.
    flutter doctor -v
    [!] Flutter (Channel [user-branch], 3.32.8, on macOS 26.0 25A5349a darwin-arm64, locale en-US) [839ms]
        ! Flutter version 3.32.8 on channel [user-branch] at /Users/deanli/dev/switcher
          Currently on an unknown channel. Run `flutter channel` to switch to an official channel.
          If that doesn't fix the issue, reinstall Flutter by following instructions at https://flutter.dev/setup.
        ! Warning: `flutter` on your path resolves to /Users/deanli/dev/stable/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/deanli/dev/switcher. Consider adding /Users/deanli/dev/switcher/bin to the front of your path.
        ! Warning: `dart` on your path resolves to /Users/deanli/dev/stable/bin/dart, which is not inside your current Flutter SDK checkout at /Users/deanli/dev/switcher. Consider adding /Users/deanli/dev/switcher/bin to the front of your path.
        ! Upstream repository unknown source is not a standard remote.
          Set environment variable "FLUTTER_GIT_URL" to unknown source to dismiss this error.
        • Framework revision edada7c56e (5 weeks ago), 2025-07-25 14:08:03 +0000
        • Engine revision ef0cd00091
        • Dart version 3.8.1
        • DevTools version 2.45.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 36.1.0-rc1) [1,852ms]
        • Android SDK at /Users/deanli/Library/Android/sdk
        • Platform android-Baklava-ext19, build-tools 36.1.0-rc1
        • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
          This is the JDK bundled with the latest Android Studio installation on this machine.
          To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
        • Java version OpenJDK Runtime Environment (build 21.0.7+-13880790-b1038.58)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 26.0) [1,381ms]
        • Xcode at /Applications/Xcode-26.0.0-beta.6.app/Contents/Developer
        • Build 17A5305f
        • CocoaPods version 1.16.2
    
    [✓] Chrome - develop for the web [11ms]
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2025.1) [10ms]
        • 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 21.0.7+-13880790-b1038.58)
    
    [✓] VS Code (version 1.103.2) [9ms]
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.116.0
    
    [✓] Connected device (5 available) [7.4s]
        • sdk gphone64 arm64 (mobile)           • emulator-5554             • android-arm64  • Android 16 (API 36) (emulator)
        • iPhone 16 Pro Max (wireless) (mobile) • 00008140-00194CC23A68801C • ios            • iOS 26.0 23A5330a
        • Nexus (wireless) (mobile)             • 00008020-001875E83A38002E • ios            • iOS 18.6.2 22G100
        • macOS (desktop)                       • macos                     • darwin-arm64   • macOS 26.0 25A5349a darwin-arm64
        • Chrome (web)                          • chrome                    • web-javascript • Google Chrome 139.0.7258.140
        ! Error: Browsing on the local area network for iPhone. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac.
          The device must be opted into Developer Mode to connect wirelessly. (code -27)
        ! Error: Browsing on the local area network for Dean’s iPad. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac.
          The device must be opted into Developer Mode to connect wirelessly. (code -27)
    
    [✓] Network resources [1,014ms]
        • All expected network resources are available.
    
    ! Doctor found issues in 1 category.
    
    [✓] Flutter (Channel stable, 3.35.2, on macOS 26.0 25A5349a darwin-arm64, locale en-US) [755ms]
        • Flutter version 3.35.2 on channel stable at /Users/deanli/dev/stable
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 05db968908 (7 days ago), 2025-08-25 10:21:35 -0700
        • Engine revision a8bfdfc394
        • Dart version 3.9.0
        • 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-lldb-debugging
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 36.1.0-rc1) [3.5s]
        • Android SDK at /Users/deanli/Library/Android/sdk
        • Emulator version 36.1.9.0 (build_id 13823996) (CL:N/A)
        • Platform android-Baklava-ext19, build-tools 36.1.0-rc1
        • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
          This is the JDK bundled with the latest Android Studio installation on this machine.
          To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
        • Java version OpenJDK Runtime Environment (build 21.0.7+-13880790-b1038.58)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 26.0) [1,429ms]
        • Xcode at /Applications/Xcode-26.0.0-beta.6.app/Contents/Developer
        • Build 17A5305f
        • CocoaPods version 1.16.2
    
    [✓] Chrome - develop for the web [7ms]
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2025.1) [6ms]
        • 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 21.0.7+-13880790-b1038.58)
    
    [✓] VS Code (version 1.103.2) [5ms]
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.116.0
    
    [✓] Connected device (5 available) [14.0s]
        • sdk gphone64 arm64 (mobile)           • emulator-5554             • android-arm64  • Android 16 (API 36) (emulator)
        • iPhone 16 Pro Max (wireless) (mobile) • 00008140-00194CC23A68801C • ios            • iOS 26.0 23A5330a
        • Nexus (wireless) (mobile)             • 00008020-001875E83A38002E • ios            • iOS 18.6.2 22G100
        • macOS (desktop)                       • macos                     • darwin-arm64   • macOS 26.0 25A5349a darwin-arm64
        • Chrome (web)                          • chrome                    • web-javascript • Google Chrome 139.0.7258.140
        ! Error: Browsing on the local area network for iPhone. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac.
          The device must be opted into Developer Mode to connect wirelessly. (code -27)
        ! Error: Browsing on the local area network for Dean’s iPad. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac.
          The device must be opted into Developer Mode to connect wirelessly. (code -27)
    
    [✓] Network resources [1,514ms]
        • All expected network resources are available.
    
    • No issues found!
    
    [!] Flutter (Channel master, 3.36.0-1.0.pre-366, on macOS 26.0 25A5349a darwin-arm64, locale en-US) [2.6s]
        • Flutter version 3.36.0-1.0.pre-366 on channel master at /Users/deanli/dev/master
        ! Warning: `flutter` on your path resolves to /Users/deanli/dev/stable/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/deanli/dev/master. Consider adding /Users/deanli/dev/master/bin to the front of your path.
        ! Warning: `dart` on your path resolves to /Users/deanli/dev/stable/bin/dart, which is not inside your current Flutter SDK checkout at /Users/deanli/dev/master. Consider adding /Users/deanli/dev/master/bin to the front of your path.
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision c24e1b7838 (20 hours ago), 2025-08-31 12:43:27 -0400
        • Engine revision c24e1b7838
        • Dart version 3.10.0 (build 3.10.0-158.0.dev)
        • DevTools version 2.50.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.
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 36.1.0-rc1) [1,543ms]
        • Android SDK at /Users/deanli/Library/Android/sdk
        • Emulator version 36.1.9.0 (build_id 13823996) (CL:N/A)
        • Platform android-Baklava-ext19, build-tools 36.1.0-rc1
        • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
          This is the JDK bundled with the latest Android Studio installation on this machine.
          To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
        • Java version OpenJDK Runtime Environment (build 21.0.7+-13880790-b1038.58)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 26.0) [1,050ms]
        • Xcode at /Applications/Xcode-26.0.0-beta.6.app/Contents/Developer
        • Build 17A5305f
        • CocoaPods version 1.16.2
    
    [✓] Chrome - develop for the web [6ms]
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Connected device (5 available) [6.6s]
        • sdk gphone64 arm64 (mobile)           • emulator-5554             • android-arm64  • Android 16 (API 36) (emulator)
        • iPhone 16 Pro Max (wireless) (mobile) • 00008140-00194CC23A68801C • ios            • iOS 26.0 23A5330a
        • Nexus (wireless) (mobile)             • 00008020-001875E83A38002E • ios            • iOS 18.6.2 22G100
        • macOS (desktop)                       • macos                     • darwin-arm64   • macOS 26.0 25A5349a darwin-arm64
        • Chrome (web)                          • chrome                    • web-javascript • Google Chrome 139.0.7258.140
        ! Error: Browsing on the local area network for iPhone. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac.
          The device must be opted into Developer Mode to connect wirelessly. (code -27)
        ! Error: Browsing on the local area network for Dean’s iPad. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac.
          The device must be opted into Developer Mode to connect wirelessly. (code -27)
    
    [✓] Network resources [986ms]
        • All expected network resources are available.
    
    ! Doctor found issues in 1 category.
    
    
  3. added
    c: regressionIt was better in the past than it is now
    frameworkflutter/packages/flutter repository. See also f: labels.
    p: cupertino_uicupertino_ui package in flutter/packages
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    team-designOwned by Design Languages team
    and removed
    in triagePresently being triaged by the triage team
    on Sep 1, 2025
  4. added
    P2Important issues not at the top of the work list
    triaged-designTriaged by Design Languages team
    on Sep 3, 2025
  5. added
    r: fixedIssue is closed as already fixed in a newer version
    on Sep 9, 2025
  6. github-actions commented on Sep 23, 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.

  7. locked as resolved and limited conversation to collaborators on Sep 23, 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 listc: regressionIt was better in the past than it is nowfound in release: 3.35Found to occur in 3.35found in release: 3.36Found to occur in 3.36frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: cupertino_uicupertino_ui package in flutter/packagesr: fixedIssue is closed as already fixed in a newer versionteam-designOwned by Design Languages teamtriaged-designTriaged by Design Languages team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions