From b0e5a5ca67b9b6b1e1744b008377bbb1160e2292 Mon Sep 17 00:00:00 2001 From: Tirth Date: Thu, 7 Sep 2023 00:03:00 +0530 Subject: [PATCH] Add `CheckedPopupMenuItem.onTap` callback (#134000) Adds parent prop `onTap` to CheckedPopupMenuItem. Fixes #127800 --- .../flutter/lib/src/material/popup_menu.dart | 1 + .../test/material/popup_menu_test.dart | 45 +++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/packages/flutter/lib/src/material/popup_menu.dart b/packages/flutter/lib/src/material/popup_menu.dart index cc87623e6330..4d81e0959daa 100644 --- a/packages/flutter/lib/src/material/popup_menu.dart +++ b/packages/flutter/lib/src/material/popup_menu.dart @@ -486,6 +486,7 @@ class CheckedPopupMenuItem extends PopupMenuItem { super.labelTextStyle, super.mouseCursor, super.child, + super.onTap, }); /// Whether to display a checkmark next to the menu item. diff --git a/packages/flutter/test/material/popup_menu_test.dart b/packages/flutter/test/material/popup_menu_test.dart index fcc0fa1f8063..79e3a7f6f6b1 100644 --- a/packages/flutter/test/material/popup_menu_test.dart +++ b/packages/flutter/test/material/popup_menu_test.dart @@ -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( + child: const Text('button'), + itemBuilder: (BuildContext context) { + return >[ + CheckedPopupMenuItem( + onTap: () { + count += 1; + }, + value: 'item1', + child: const Text('Item with onTap'), + ), + const CheckedPopupMenuItem( + 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, '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, 'Item without onTap')); + await tester.pumpAndSettle(); + expect(count, 1); + }); } class TestApp extends StatelessWidget {