Skip to content

Commit 4daecc2

Browse files
committed
more refactoring
1 parent e585be7 commit 4daecc2

File tree

2 files changed

+34
-34
lines changed

2 files changed

+34
-34
lines changed

flutter/lib/src/user_interaction/sentry_user_interaction_widget.dart

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -331,10 +331,10 @@ class _SentryUserInteractionWidgetState
331331
return;
332332
}
333333

334-
Map<String, dynamic>? data;
335-
if ((_options?.sendDefaultPii ?? false) && info.description.isNotEmpty) {
336-
data = {};
337-
data['label'] = info.description;
334+
Map<String, dynamic>? data = {};
335+
final description = _findDescriptionOf(info.element);
336+
if (description.isNotEmpty) {
337+
data['label'] = description;
338338
}
339339

340340
final crumb = Breadcrumb.userInteraction(
@@ -417,42 +417,45 @@ class _SentryUserInteractionWidgetState
417417
}
418418

419419
String _findDescriptionOf(Element element) {
420-
final widget = element.widget;
421-
final allowText = widget is ButtonStyleButton ||
422-
widget is MaterialButton ||
423-
widget is CupertinoButton;
424420
var description = '';
425421

426-
// traverse tree to find a suiting element
427-
void descriptionFinder(Element element) {
428-
bool foundDescription = false;
429-
422+
if (_options?.sendDefaultPii ?? false) {
430423
final widget = element.widget;
431-
if (allowText && widget is Text) {
432-
final data = widget.data;
433-
if (data != null && data.isNotEmpty) {
434-
description = data;
435-
foundDescription = true;
436-
}
437-
} else if (widget is Semantics) {
438-
if (widget.properties.label?.isNotEmpty ?? false) {
439-
description = widget.properties.label!;
440-
foundDescription = true;
424+
final allowText = widget is ButtonStyleButton ||
425+
widget is MaterialButton ||
426+
widget is CupertinoButton;
427+
428+
// traverse tree to find a suiting element
429+
void descriptionFinder(Element element) {
430+
bool foundDescription = false;
431+
432+
final widget = element.widget;
433+
if (allowText && widget is Text) {
434+
final data = widget.data;
435+
if (data != null && data.isNotEmpty) {
436+
description = data;
437+
foundDescription = true;
438+
}
439+
} else if (widget is Semantics) {
440+
if (widget.properties.label?.isNotEmpty ?? false) {
441+
description = widget.properties.label!;
442+
foundDescription = true;
443+
}
444+
} else if (widget is Icon) {
445+
if (widget.semanticLabel?.isNotEmpty ?? false) {
446+
description = widget.semanticLabel!;
447+
foundDescription = true;
448+
}
441449
}
442-
} else if (widget is Icon) {
443-
if (widget.semanticLabel?.isNotEmpty ?? false) {
444-
description = widget.semanticLabel!;
445-
foundDescription = true;
450+
451+
if (!foundDescription) {
452+
element.visitChildren(descriptionFinder);
446453
}
447454
}
448455

449-
if (!foundDescription) {
450-
element.visitChildren(descriptionFinder);
451-
}
456+
element.visitChildren(descriptionFinder);
452457
}
453458

454-
element.visitChildren(descriptionFinder);
455-
456459
return description;
457460
}
458461

@@ -496,7 +499,6 @@ class _SentryUserInteractionWidgetState
496499
if (type != null) {
497500
tappedWidget = UserInteractionInfo(
498501
element: element,
499-
description: _findDescriptionOf(element),
500502
type: type,
501503
);
502504
}

flutter/lib/src/user_interaction/user_interaction_info.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ import 'package:meta/meta.dart';
44
@internal
55
class UserInteractionInfo {
66
final Element element;
7-
final String description;
87
final String type;
98

109
const UserInteractionInfo({
1110
required this.element,
12-
required this.description,
1311
required this.type,
1412
});
1513
}

0 commit comments

Comments
 (0)