Skip to content

Commit 313ebc2

Browse files
committed
add type
1 parent af50b36 commit 313ebc2

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

flutter/lib/src/sentry_user_interaction_widget.dart

+24-10
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class _SentryUserInteractionWidgetState
3939
extends State<SentryUserInteractionWidget> {
4040
int? _lastPointerId;
4141
Offset? _lastPointerDownLocation;
42-
Widget? _lastWidget;
42+
TappedWidget? _lastTappedWidget;
4343
ISentrySpan? _activeTransaction;
4444

4545
Hub get _hub => widget._hub;
@@ -82,9 +82,18 @@ class _SentryUserInteractionWidgetState
8282

8383
void _onTappedAt(Offset position) {
8484
final tappedWidget = _getElementAt(position);
85-
if (tappedWidget == null || tappedWidget.keyValue == null) {
85+
final keyValue = tappedWidget?.keyValue;
86+
if (tappedWidget == null || keyValue == null) {
8687
return;
8788
}
89+
final element = tappedWidget.element;
90+
91+
// String? currentRouteName;
92+
// if (element is StatefulElement) {
93+
// currentRouteName = ModalRoute.of(element.state.context)?.settings.name;
94+
// } else if (element is StatelessElement) {
95+
96+
// }
8897

8998
Map<String, dynamic>? data;
9099
// ignore: invalid_use_of_internal_member
@@ -99,12 +108,12 @@ class _SentryUserInteractionWidgetState
99108
if (_options?.enableUserInteractionBreadcrumbs ?? false) {
100109
final crumb = Breadcrumb.userInteraction(
101110
subCategory: category,
102-
viewId: tappedWidget.keyValue,
111+
viewId: keyValue,
103112
// viewClass: tappedWidget.element.widget.runtimeType.toString(),
104113
viewClass: tappedWidget.type, // to avoid minification
105114
data: data,
106115
);
107-
_hub.addBreadcrumb(crumb, hint: tappedWidget.element.widget);
116+
_hub.addBreadcrumb(crumb, hint: element.widget);
108117
}
109118

110119
// ignore: invalid_use_of_internal_member
@@ -115,16 +124,15 @@ class _SentryUserInteractionWidgetState
115124

116125
// TODO: name should be screenName.widgetName, maybe get from router?
117126
final transactionContext = SentryTransactionContext(
118-
tappedWidget.keyValue!,
127+
keyValue,
119128
'ui.action.$category',
120129
transactionNameSource: SentryTransactionNameSource.component,
121130
);
122131

123-
// TODO: check if when starting a new child, the timer is reset
124-
// TODO: check the type of the event in the widget
125132
final activeTransaction = _activeTransaction;
126133
if (activeTransaction != null) {
127-
if (_lastWidget == tappedWidget.element.widget &&
134+
if (_lastTappedWidget?.element.widget == element.widget &&
135+
_lastTappedWidget?.eventType == tappedWidget.eventType &&
128136
!activeTransaction.finished) {
129137
// ignore: invalid_use_of_internal_member
130138
activeTransaction.scheduleFinish();
@@ -137,11 +145,11 @@ class _SentryUserInteractionWidgetState
137145
}
138146
});
139147
_activeTransaction = null;
140-
_lastWidget = null;
148+
_lastTappedWidget = null;
141149
}
142150
}
143151

144-
_lastWidget = tappedWidget.element.widget;
152+
_lastTappedWidget = tappedWidget;
145153

146154
bool hasRunningTransaction = false;
147155
_hub.configureScope((scope) {
@@ -259,6 +267,7 @@ class _SentryUserInteractionWidgetState
259267
element: element,
260268
description: _findDescriptionOf(element, true),
261269
type: 'ButtonStyleButton',
270+
eventType: 'onClick',
262271
);
263272
}
264273
} else if (widget is MaterialButton) {
@@ -267,6 +276,7 @@ class _SentryUserInteractionWidgetState
267276
element: element,
268277
description: _findDescriptionOf(element, true),
269278
type: 'MaterialButton',
279+
eventType: 'onClick',
270280
);
271281
}
272282
} else if (widget is CupertinoButton) {
@@ -275,6 +285,7 @@ class _SentryUserInteractionWidgetState
275285
element: element,
276286
description: _findDescriptionOf(element, true),
277287
type: 'CupertinoButton',
288+
eventType: 'onPressed',
278289
);
279290
}
280291
} else if (widget is InkWell) {
@@ -283,6 +294,7 @@ class _SentryUserInteractionWidgetState
283294
element: element,
284295
description: _findDescriptionOf(element, false),
285296
type: 'InkWell',
297+
eventType: 'onTap',
286298
);
287299
}
288300
} else if (widget is IconButton) {
@@ -291,6 +303,7 @@ class _SentryUserInteractionWidgetState
291303
element: element,
292304
description: _findDescriptionOf(element, false),
293305
type: 'IconButton',
306+
eventType: 'onPressed',
294307
);
295308
}
296309
} else if (widget is GestureDetector) {
@@ -299,6 +312,7 @@ class _SentryUserInteractionWidgetState
299312
element: element,
300313
description: '',
301314
type: 'GestureDetector',
315+
eventType: 'onTap',
302316
);
303317
}
304318
}

flutter/lib/src/widget_click/tapped_widget.dart

+2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ class TappedWidget {
44
final Element element;
55
final String description;
66
final String type;
7+
final String eventType;
78

89
const TappedWidget({
910
required this.element,
1011
required this.description,
1112
required this.type,
13+
required this.eventType,
1214
});
1315

1416
String? get keyValue {

0 commit comments

Comments
 (0)