Skip to content

Commit

Permalink
Add CheckedPopupMenuItem.onTap callback (#134000)
Browse files Browse the repository at this point in the history
Adds parent prop `onTap` to CheckedPopupMenuItem.

Fixes #127800
  • Loading branch information
piedcipher authored Sep 6, 2023
1 parent ee0a15d commit b0e5a5c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/flutter/lib/src/material/popup_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ class CheckedPopupMenuItem<T> extends PopupMenuItem<T> {
super.labelTextStyle,
super.mouseCursor,
super.child,
super.onTap,
});

/// Whether to display a checkmark next to the menu item.
Expand Down
45 changes: 45 additions & 0 deletions packages/flutter/test/material/popup_menu_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3740,6 +3740,51 @@ void main() {
expect(_labelStyle(tester, 'Item 1')!.fontWeight, customTextStyle.fontWeight);
expect(_labelStyle(tester, 'Item 1')!.fontStyle, customTextStyle.fontStyle);
});

testWidgets('CheckedPopupMenuItem.onTap callback is called when defined', (WidgetTester tester) async {
int count = 0;
await tester.pumpWidget(
TestApp(
textDirection: TextDirection.ltr,
child: Material(
child: RepaintBoundary(
child: PopupMenuButton<String>(
child: const Text('button'),
itemBuilder: (BuildContext context) {
return <PopupMenuItem<String>>[
CheckedPopupMenuItem<String>(
onTap: () {
count += 1;
},
value: 'item1',
child: const Text('Item with onTap'),
),
const CheckedPopupMenuItem<String>(
value: 'item2',
child: Text('Item without onTap'),
),
];
},
),
),
),
),
);

// Tap a checked menu item with onTap.
await tester.tap(find.text('button'));
await tester.pumpAndSettle();
await tester.tap(find.widgetWithText(CheckedPopupMenuItem<String>, 'Item with onTap'));
await tester.pumpAndSettle();
expect(count, 1);

// Tap a checked menu item without onTap.
await tester.tap(find.text('button'));
await tester.pumpAndSettle();
await tester.tap(find.widgetWithText(CheckedPopupMenuItem<String>, 'Item without onTap'));
await tester.pumpAndSettle();
expect(count, 1);
});
}

class TestApp extends StatelessWidget {
Expand Down

0 comments on commit b0e5a5c

Please sign in to comment.