Skip to content

Commit 0be962b

Browse files
SentryUserInteractionWidget: add support for PopupMenuButton and PopupMenuItem (#1361)
Co-authored-by: Manoel Aranda Neto <[email protected]> Co-authored-by: Manoel Aranda Neto <[email protected]>
1 parent 8e133ad commit 0be962b

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
### Features
6+
7+
- SentryUserInteractionWidget: add support for PopupMenuButton and PopupMenuItem ([#1361](https://github.com/getsentry/sentry-dart/pull/1361))
8+
59
### Fixes
610

711
- Fix `SentryUserInteractionWidget` throwing when Sentry is not enabled ([#1363](https://github.com/getsentry/sentry-dart/pull/1363))

flutter/lib/src/user_interaction/sentry_user_interaction_widget.dart

+19-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ Element? _clickTrackerElement;
219219
///
220220
/// It's supported by the most common [Widget], for example:
221221
/// [ButtonStyleButton], [MaterialButton], [CupertinoButton], [InkWell],
222-
/// and [IconButton].
222+
/// [IconButton], [PopupMenuButton] and [PopupMenuItem].
223223
/// Mostly for onPressed, onTap, and onLongPress events
224224
///
225225
/// Example on how to set up:
@@ -542,6 +542,24 @@ class _SentryUserInteractionWidgetState
542542
eventType: 'onPressed',
543543
);
544544
}
545+
} else if (widget is PopupMenuButton) {
546+
if (widget.enabled) {
547+
return UserInteractionWidget(
548+
element: element,
549+
description: _findDescriptionOf(element, false),
550+
type: 'PopupMenuButton',
551+
eventType: 'onTap',
552+
);
553+
}
554+
} else if (widget is PopupMenuItem) {
555+
if (widget.enabled) {
556+
return UserInteractionWidget(
557+
element: element,
558+
description: _findDescriptionOf(element, false),
559+
type: 'PopupMenuItem',
560+
eventType: 'onTap',
561+
);
562+
}
545563
}
546564

547565
return null;

flutter/test/user_interaction/sentry_user_interaction_widget_test.dart

+45
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,42 @@ void main() {
120120
expect(crumb?.data?['label'], 'Button 5');
121121
});
122122
});
123+
124+
testWidgets('Add crumb for PopupMenuButton', (tester) async {
125+
await tester.runAsync(() async {
126+
final sut = fixture.getSut();
127+
128+
await tapMe(tester, sut, 'popup_menu_button');
129+
130+
Breadcrumb? crumb;
131+
fixture.hub.configureScope((scope) {
132+
crumb = scope.breadcrumbs.last;
133+
});
134+
expect(crumb?.category, 'ui.click');
135+
expect(crumb?.data?['view.id'], 'popup_menu_button');
136+
expect(crumb?.data?['view.class'], 'PopupMenuButton');
137+
});
138+
});
139+
140+
testWidgets('Add crumb for PopupMenuItem', (tester) async {
141+
await tester.runAsync(() async {
142+
final sut = fixture.getSut();
143+
144+
// open the popup menu and wait for the animation to complete
145+
await tapMe(tester, sut, 'popup_menu_button');
146+
await tester.pumpAndSettle();
147+
148+
await tapMe(tester, sut, 'popup_menu_item_1');
149+
150+
Breadcrumb? crumb;
151+
fixture.hub.configureScope((scope) {
152+
crumb = scope.breadcrumbs.last;
153+
});
154+
expect(crumb?.category, 'ui.click');
155+
expect(crumb?.data?['view.id'], 'popup_menu_item_1');
156+
expect(crumb?.data?['view.class'], 'PopupMenuItem');
157+
});
158+
});
123159
});
124160

125161
group('$SentryUserInteractionWidget performance', () {
@@ -363,6 +399,15 @@ class Page1 extends StatelessWidget {
363399
},
364400
child: const Text('Go to page 2'),
365401
),
402+
PopupMenuButton(
403+
key: ValueKey('popup_menu_button'),
404+
itemBuilder: (_) => [
405+
PopupMenuItem<void>(
406+
key: ValueKey('popup_menu_item_1'),
407+
child: Text('first item'),
408+
),
409+
],
410+
),
366411
],
367412
),
368413
),

0 commit comments

Comments
 (0)