diff --git a/CHANGELOG.md b/CHANGELOG.md index 47f45456c3..0e9d0b26e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +### Fixes + +- Fix `SentryUserInteractionWidget` throwing when Sentry is not enabled ([#1363](https://github.com/getsentry/sentry-dart/pull/1363)) + ## 7.3.0 ### Features diff --git a/flutter/lib/src/user_interaction/sentry_user_interaction_widget.dart b/flutter/lib/src/user_interaction/sentry_user_interaction_widget.dart index 2e17b39578..a33d96435d 100644 --- a/flutter/lib/src/user_interaction/sentry_user_interaction_widget.dart +++ b/flutter/lib/src/user_interaction/sentry_user_interaction_widget.dart @@ -251,7 +251,10 @@ class SentryUserInteractionWidget extends StatefulWidget { SentryFlutterOptions? get _options => // ignore: invalid_use_of_internal_member - _hub.options as SentryFlutterOptions?; + _hub.options is SentryFlutterOptions + // ignore: invalid_use_of_internal_member + ? _hub.options as SentryFlutterOptions + : null; @override StatefulElement createElement() { diff --git a/flutter/test/user_interaction/sentry_user_interaction_widget_test.dart b/flutter/test/user_interaction/sentry_user_interaction_widget_test.dart index 5c6733bb47..d62a54ad2e 100644 --- a/flutter/test/user_interaction/sentry_user_interaction_widget_test.dart +++ b/flutter/test/user_interaction/sentry_user_interaction_widget_test.dart @@ -1,5 +1,4 @@ @TestOn('vm') - // ignore_for_file: invalid_use_of_internal_member import 'dart:async'; @@ -14,13 +13,26 @@ import '../mocks.dart'; import '../mocks.mocks.dart'; void main() { - group('$SentryUserInteractionWidget crumbs', () { - late Fixture fixture; - setUp(() async { - fixture = Fixture(); - TestWidgetsFlutterBinding.ensureInitialized(); - }); + late Fixture fixture; + setUp(() async { + fixture = Fixture(); + TestWidgetsFlutterBinding.ensureInitialized(); + }); + + testWidgets( + '$SentryUserInteractionWidget does not throw cast exception when Sentry is disabled', + (tester) async { + await tester.runAsync(() async { + await tester.pumpWidget( + SentryUserInteractionWidget( + child: MaterialApp(), + ), + ); + }); + }, + ); + group('$SentryUserInteractionWidget crumbs', () { testWidgets('Add crumb for MaterialButton', (tester) async { await tester.runAsync(() async { final sut = fixture.getSut();