Skip to content

Commit 902a697

Browse files
Make sure that a PopupMenuButton doesn't crash in 0x0 environment (flutter#177493)
This is my attempt to handle flutter#6537 for the PopupMenuButton widget. --------- Co-authored-by: Tong Mu <dkwingsmt@users.noreply.github.com>
1 parent 4499cf6 commit 902a697

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

packages/flutter/test/material/popup_menu_test.dart

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4851,6 +4851,29 @@ void main() {
48514851
checkPopupMenu(popupMenuTheme2);
48524852
});
48534853

4854+
testWidgets('PopupMenuButton does not crash at zero area', (WidgetTester tester) async {
4855+
// This test case only verifies the layout of the button itself, not the
4856+
// overlay, because there doesn't seem to be a way to open the menu at zero
4857+
// area. Though, this should be sufficient since the overlay has been verified
4858+
// by similar tests for MenuAnchor and PopupMenuItem.
4859+
tester.view.physicalSize = Size.zero;
4860+
addTearDown(tester.view.reset);
4861+
await tester.pumpWidget(
4862+
MaterialApp(
4863+
home: Center(
4864+
child: SizedBox.shrink(
4865+
child: PopupMenuButton<String>(
4866+
itemBuilder: (BuildContext context) => <PopupMenuItem<String>>[
4867+
const PopupMenuItem<String>(value: 'X', child: Text('X')),
4868+
],
4869+
),
4870+
),
4871+
),
4872+
),
4873+
);
4874+
expect(tester.getSize(find.byType(PopupMenuButton<String>)), Size.zero);
4875+
});
4876+
48544877
testWidgets('PopupMenuDivider does not crash at zero area', (WidgetTester tester) async {
48554878
await tester.pumpWidget(
48564879
const MaterialApp(

0 commit comments

Comments
 (0)