From 40771ddaeb6fc4d89b381cfd29ee2bd197e39faa Mon Sep 17 00:00:00 2001 From: Taha Tesser Date: Fri, 4 Oct 2024 00:36:15 +0300 Subject: [PATCH] Fix `MacosPulldownMenuItem.onTap` doesn't open alert dialog --- CHANGELOG.md | 3 ++ lib/src/buttons/pulldown_button.dart | 2 +- pubspec.yaml | 2 +- test/buttons/pulldown_button_test.dart | 53 ++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d87d8aa..2717b638 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## [2.1.1] +* Fixed a bug where `MacosPulldownMenuItem` would not show an alert dialog when tapped. + ## [2.1.0] * Updated dependencies * Support macOS 15 diff --git a/lib/src/buttons/pulldown_button.dart b/lib/src/buttons/pulldown_button.dart index 37c0e7d1..09702afa 100644 --- a/lib/src/buttons/pulldown_button.dart +++ b/lib/src/buttons/pulldown_button.dart @@ -65,8 +65,8 @@ class _MacosPulldownMenuItemButtonState final MacosPulldownMenuEntry menuEntity = widget.route.items[widget.itemIndex].item!; if (menuEntity is MacosPulldownMenuItem) { - menuEntity.onTap?.call(); Navigator.pop(context); + menuEntity.onTap?.call(); } } diff --git a/pubspec.yaml b/pubspec.yaml index ca5712a3..65235877 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: macos_ui description: Flutter widgets and themes implementing the current macOS design language. -version: 2.1.0 +version: 2.1.1 homepage: "https://macosui.dev" repository: "https://github.com/GroovinChip/macos_ui" diff --git a/test/buttons/pulldown_button_test.dart b/test/buttons/pulldown_button_test.dart index 668914d0..14c38fe6 100644 --- a/test/buttons/pulldown_button_test.dart +++ b/test/buttons/pulldown_button_test.dart @@ -180,5 +180,58 @@ void main() { ], ); }); + + testWidgets( + 'MacosPulldownMenuItem.onTap shows alert dialog', + (WidgetTester tester) async { + await tester.pumpWidget( + MacosApp( + home: MacosWindow( + child: MacosScaffold( + children: [ + ContentArea( + builder: (context, _) { + return Center( + child: MacosPulldownButton( + title: "test", + items: [ + MacosPulldownMenuItem( + title: const Text('Open Alert Dialog'), + onTap: () => showMacosAlertDialog( + context: context, + builder: (context) => MacosAlertDialog( + appIcon: const FlutterLogo(size: 64), + title: const Text('Title'), + message: const Text('Message'), + primaryButton: PushButton( + controlSize: ControlSize.large, + onPressed: Navigator.of(context).pop, + child: const Text('Close'), + ), + ), + ), + ), + ], + )); + }, + ), + ], + ), + ), + ), + ); + + // Tap the first time + await tester.tap(find.text('test')); + await tester.pumpAndSettle(); + await tester.tap(find.text('Open Alert Dialog')); + await tester.pumpAndSettle(); + + expect(find.text('Open Alert Dialog'), findsNothing); + expect(find.text('Title'), findsOneWidget); + expect(find.text('Message'), findsOneWidget); + expect(find.text('Close'), findsOneWidget); + }, + ); }); }