-
Notifications
You must be signed in to change notification settings - Fork 29.2k
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