Skip to content

Commit 0c1a14e

Browse files
authored
Fix MacosPulldownMenuItem.onTap doesn't open alert dialog (#520)
1 parent 6313ee5 commit 0c1a14e

File tree

4 files changed

+59
-2
lines changed

4 files changed

+59
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## [2.1.1]
2+
* Fixed a bug where `MacosPulldownMenuItem` would not show an alert dialog when tapped.
3+
14
## [2.1.0]
25
* Updated dependencies
36
* Support macOS 15

lib/src/buttons/pulldown_button.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ class _MacosPulldownMenuItemButtonState
6565
final MacosPulldownMenuEntry menuEntity =
6666
widget.route.items[widget.itemIndex].item!;
6767
if (menuEntity is MacosPulldownMenuItem) {
68+
Navigator.of(context).pop();
6869
menuEntity.onTap?.call();
69-
Navigator.pop(context);
7070
}
7171
}
7272

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: macos_ui
22
description: Flutter widgets and themes implementing the current macOS design language.
3-
version: 2.1.0
3+
version: 2.1.1
44
homepage: "https://macosui.dev"
55
repository: "https://github.com/GroovinChip/macos_ui"
66

test/buttons/pulldown_button_test.dart

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,5 +180,59 @@ void main() {
180180
],
181181
);
182182
});
183+
184+
testWidgets(
185+
'MacosPulldownMenuItem.onTap shows alert dialog',
186+
(WidgetTester tester) async {
187+
await tester.pumpWidget(
188+
MacosApp(
189+
home: MacosWindow(
190+
child: MacosScaffold(
191+
children: [
192+
ContentArea(
193+
builder: (context, _) {
194+
return Center(
195+
child: MacosPulldownButton(
196+
title: "test",
197+
items: [
198+
MacosPulldownMenuItem(
199+
title: const Text('Open Alert Dialog'),
200+
onTap: () => showMacosAlertDialog(
201+
context: context,
202+
builder: (context) => MacosAlertDialog(
203+
appIcon: const MacosIcon(CupertinoIcons.eyedropper),
204+
title: const Text('Title'),
205+
message: const Text('Message'),
206+
primaryButton: PushButton(
207+
controlSize: ControlSize.large,
208+
onPressed: Navigator.of(context).pop,
209+
child: const Text('Close'),
210+
),
211+
),
212+
),
213+
),
214+
],
215+
));
216+
},
217+
),
218+
],
219+
),
220+
),
221+
),
222+
);
223+
224+
// Tap the pulldown button.
225+
await tester.tap(find.text('test'));
226+
await tester.pumpAndSettle();
227+
// Tap the menu item to show the alert dialog.
228+
await tester.tap(find.text('Open Alert Dialog'));
229+
await tester.pumpAndSettle();
230+
231+
expect(find.text('Open Alert Dialog'), findsNothing);
232+
expect(find.text('Title'), findsOneWidget);
233+
expect(find.text('Message'), findsOneWidget);
234+
expect(find.text('Close'), findsOneWidget);
235+
},
236+
);
183237
});
184238
}

0 commit comments

Comments
 (0)