Skip to content

Commit

Permalink
SentryUserInteractionWidget checks if the Elements are mounted before…
Browse files Browse the repository at this point in the history
… comparing them (#1339)
  • Loading branch information
marandaneto committed Mar 17, 2023
1 parent 1ab55fc commit 5aab4c5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
- [changelog](https://github.com/getsentry/sentry-cocoa/blob/main/CHANGELOG.md#831)
- [diff](https://github.com/getsentry/sentry-cocoa/compare/8.0.0...8.3.1)

### Fixes

- SentryUserInteractionWidget checks if the Elements are mounted before comparing them ([#1339](https://github.com/getsentry/sentry-dart/pull/1339))

## 7.0.0

### Features
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,11 @@ class _SentryUserInteractionWidgetState
);

final activeTransaction = _activeTransaction;
final lastElement = _lastTappedWidget?.element;
if (activeTransaction != null) {
if (_lastTappedWidget?.element.widget == element.widget &&
if (_isElementMounted(lastElement) &&
_isElementMounted(element) &&
lastElement?.widget == element.widget &&
_lastTappedWidget?.eventType == tappedWidget.eventType &&
!activeTransaction.finished) {
// ignore: invalid_use_of_internal_member
Expand Down Expand Up @@ -339,4 +342,26 @@ class _SentryUserInteractionWidgetState

return null;
}

bool _isElementMounted(Element? element) {
if (element == null) {
return false;
}
try {
// ignore: return_of_invalid_type
return (element as dynamic).mounted;
} on NoSuchMethodError catch (_) {
// mounted checks if the widget is not null.

try {
// Flutter 3.0.0 does `_widget!` and if `_widget` is null it throws.

// ignore: unnecessary_null_comparison
return element.widget != null;
} catch (_) {
// if it throws, the `_widget` is null and not mounted.
return false;
}
}
}
}

0 comments on commit 5aab4c5

Please sign in to comment.