Skip to content

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

@flowhorn

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

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 nowf: cupertinoflutter/packages/flutter/cupertino repositoryfound 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 onr: 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