File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed
flutter/lib/src/user_interaction Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change 1212 - [ changelog] ( https://github.com/getsentry/sentry-cocoa/blob/main/CHANGELOG.md#831 )
1313 - [ diff] ( https://github.com/getsentry/sentry-cocoa/compare/8.0.0...8.3.1 )
1414
15+ ### Fixes
16+
17+ - SentryUserInteractionWidget checks if the Elements are mounted before comparing them ([ #1339 ] ( https://github.com/getsentry/sentry-dart/pull/1339 ) )
18+
1519## 7.0.0
1620
1721### Features
Original file line number Diff line number Diff line change @@ -151,8 +151,11 @@ class _SentryUserInteractionWidgetState
151151 );
152152
153153 final activeTransaction = _activeTransaction;
154+ final lastElement = _lastTappedWidget? .element;
154155 if (activeTransaction != null ) {
155- if (_lastTappedWidget? .element.widget == element.widget &&
156+ if (_isElementMounted (lastElement) &&
157+ _isElementMounted (element) &&
158+ lastElement? .widget == element.widget &&
156159 _lastTappedWidget? .eventType == tappedWidget.eventType &&
157160 ! activeTransaction.finished) {
158161 // ignore: invalid_use_of_internal_member
@@ -339,4 +342,26 @@ class _SentryUserInteractionWidgetState
339342
340343 return null ;
341344 }
345+
346+ bool _isElementMounted (Element ? element) {
347+ if (element == null ) {
348+ return false ;
349+ }
350+ try {
351+ // ignore: return_of_invalid_type
352+ return (element as dynamic ).mounted;
353+ } on NoSuchMethodError catch (_) {
354+ // mounted checks if the widget is not null.
355+
356+ try {
357+ // Flutter 3.0.0 does `_widget!` and if `_widget` is null it throws.
358+
359+ // ignore: unnecessary_null_comparison
360+ return element.widget != null ;
361+ } catch (_) {
362+ // if it throws, the `_widget` is null and not mounted.
363+ return false ;
364+ }
365+ }
366+ }
342367}
You can’t perform that action at this time.
0 commit comments