Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix MenuItemButton if child is null #147485

Merged
merged 7 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/flutter/lib/src/material/menu_anchor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,7 @@ class _MenuItemButtonState extends State<MenuItemButton> {
trailingIcon: widget.trailingIcon,
hasSubmenu: false,
overflowAxis: _anchor?._orientation ?? widget.overflowAxis,
child: widget.child!,
child: widget.child ?? const SizedBox(),

Choose a reason for hiding this comment

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

Using const SizedBox.shrink(); Would be better.
See https://api.flutter.dev/flutter/widgets/Visibility-class.html

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mahmoudsaleh1997 Agreed, thank you

),
);

Expand Down
18 changes: 18 additions & 0 deletions packages/flutter/test/material/menu_anchor_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2532,6 +2532,24 @@ void main() {
..rect(color: overlayColor.withOpacity(0.1)),
);
});

testWidgets('MenuItemButton was null check operator when it child is null', (WidgetTester tester) async {
await tester.pumpWidget(
const MaterialApp(
home: Scaffold(
body: SizedBox(
width: 200,
child: MenuItemButton(
child: null,
),
),
),
),
);

// exception `Null check operator used on a null value` would be thrown.
expect(tester.takeException(), isNull);
nate-thegrate marked this conversation as resolved.
Show resolved Hide resolved
});
});

group('Layout', () {
Expand Down