Repository navigation
Description
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
- Create a minimal CupertinoApp with a CupertinoPageScaffold and a CupertinoNavigationBar.
- Place a widget in the trailing slot that calls MediaQuery.of(context).size.
- 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
realmeylisdev commentedon Aug 31, 2025
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:
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:
Recommended Triage Classification
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.
Fix CupertinoNavigationBar MediaQuery regression (flutter#174771)
Fix CupertinoNavigationBar MediaQuery regression (flutter#174771)
Fix CupertinoNavigationBar MediaQuery regression (flutter#174771)
danagbemava-nc commentedon Sep 1, 2025
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)
flutter run (stable 3.35+)
flutter doctor -v
Nav bar static components respect ambient MediaQueryData (#174673)
Nav bar static components respect ambient MediaQueryData (flutter#174673
github-actions commentedon Sep 23, 2025
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 -vand a minimal reproduction of the issue.