Visitar URL original
Nav bar static components respect ambient MediaQueryData by victorsanni · Pull Request #174673 · flutter/flutter · GitHub
Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix test
  • Loading branch information
victorsanni committed Sep 4, 2025
commit 9f503f65f0a26dddec30a164af4371a8c6573fb8
51 changes: 26 additions & 25 deletions packages/flutter/test/cupertino/nav_bar_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,14 @@ void main() {
});

testWidgets('Nav bar static components respect MediaQueryData', (WidgetTester tester) async {
count = 0x000000;
const double value = 10.0;
Comment thread
victorsanni marked this conversation as resolved.
Resolved

void expectCustomMediaQueryData(BuildContext context) {
expect(MediaQuery.platformBrightnessOf(context), Brightness.dark);

@dkwingsmt dkwingsmt Sep 4, 2025 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, but is it ok if it doesn't check the value anymore? (Which I'm ok with since the original issue wasn't about custom values)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with that is a future change might copy over only the mediaQueryData brightness leaving the other properties out. And we want to prevent against that regression. But MediaQueryData has many properties, so I'm thinking of testing with a subset of those properties numerous enough to protect against regression.

What do you think is the optimal approach here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think this is sufficient. Just a few is enough to verify our approach here, and thoroughly testing copyWith should be done in MediaQueryData's tests.

expect(MediaQuery.devicePixelRatioOf(context), value);
expect(MediaQuery.viewInsetsOf(context), const EdgeInsets.all(value));
}

await tester.pumpWidget(
CupertinoApp(
home: MediaQuery(
Expand All @@ -463,20 +469,31 @@ void main() {
platformBrightness: Brightness.dark,
),
child: CupertinoNavigationBar(
leading: CupertinoButton(
onPressed: () {},
child: const _ExpectCustomMediaQuery(value: value, index: 0x000001),
leading: Builder(
builder: (BuildContext context) {
expectCustomMediaQueryData(context);
return CupertinoButton(onPressed: () {}, child: const Text('leading'));
},
),
middle: Builder(
builder: (BuildContext context) {
expectCustomMediaQueryData(context);
return CupertinoButton(onPressed: () {}, child: const Text('middle'));
},
),
middle: const _ExpectCustomMediaQuery(value: value, index: 0x000100),
trailing: CupertinoButton(
onPressed: () {},
child: const _ExpectCustomMediaQuery(value: value, index: 0x010000),
trailing: Builder(
builder: (BuildContext context) {
expectCustomMediaQueryData(context);
return CupertinoButton(onPressed: () {}, child: const Text('trailing'));
},
),
),
),
),
);
expect(count, 0x010101);
expect(find.text('leading'), findsOneWidget);
expect(find.text('middle'), findsOneWidget);
expect(find.text('trailing'), findsOneWidget);
});

testWidgets('No slivers with no large titles', (WidgetTester tester) async {
Expand Down Expand Up @@ -3214,19 +3231,3 @@ class _ExpectStyles extends StatelessWidget {
return Container();
}
}

class _ExpectCustomMediaQuery extends StatelessWidget {
const _ExpectCustomMediaQuery({required this.value, required this.index});

final double value;
final int index;

@override
Widget build(BuildContext context) {
expect(MediaQuery.platformBrightnessOf(context), Brightness.dark);
expect(MediaQuery.devicePixelRatioOf(context), value);
expect(MediaQuery.viewInsetsOf(context), EdgeInsets.all(value));
count += index;
return Container();
}
}