File tree 2 files changed +30
-1
lines changed
flutter/lib/src/user_interaction 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change 12
12
- [ changelog] ( https://github.com/getsentry/sentry-cocoa/blob/main/CHANGELOG.md#831 )
13
13
- [ diff] ( https://github.com/getsentry/sentry-cocoa/compare/8.0.0...8.3.1 )
14
14
15
+ ### Fixes
16
+
17
+ - SentryUserInteractionWidget checks if the Elements are mounted before comparing them ([ #1339 ] ( https://github.com/getsentry/sentry-dart/pull/1339 ) )
18
+
15
19
## 7.0.0
16
20
17
21
### Features
Original file line number Diff line number Diff line change @@ -151,8 +151,11 @@ class _SentryUserInteractionWidgetState
151
151
);
152
152
153
153
final activeTransaction = _activeTransaction;
154
+ final lastElement = _lastTappedWidget? .element;
154
155
if (activeTransaction != null ) {
155
- if (_lastTappedWidget? .element.widget == element.widget &&
156
+ if (_isElementMounted (lastElement) &&
157
+ _isElementMounted (element) &&
158
+ lastElement? .widget == element.widget &&
156
159
_lastTappedWidget? .eventType == tappedWidget.eventType &&
157
160
! activeTransaction.finished) {
158
161
// ignore: invalid_use_of_internal_member
@@ -339,4 +342,26 @@ class _SentryUserInteractionWidgetState
339
342
340
343
return null ;
341
344
}
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
+ }
342
367
}
You can’t perform that action at this time.
0 commit comments