Skip to content

Commit b228520

Browse files
committed
move wrapper to own file to fix analyzer warnign
1 parent e037114 commit b228520

5 files changed

+74
-68
lines changed

flutter/lib/src/integrations/on_error_integration.dart

Lines changed: 2 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
import 'dart:ui';
2-
3-
import 'package:meta/meta.dart';
41
import 'package:sentry/sentry.dart';
5-
import '../sentry_flutter_options.dart';
6-
72
// ignore: implementation_imports
83
import 'package:sentry/src/utils/stacktrace_utils.dart';
4+
import '../sentry_flutter_options.dart';
5+
import '../utils/platform_dispatcher_wrapper.dart';
96

107
typedef ErrorCallback = bool Function(Object exception, StackTrace stackTrace);
118

@@ -110,66 +107,3 @@ class OnErrorIntegration implements Integration<SentryFlutterOptions> {
110107
}
111108
}
112109
}
113-
114-
/// This class wraps the `this as dynamic` hack in a type-safe manner.
115-
/// It helps to introduce code, which uses newer features from Flutter
116-
/// without breaking Sentry on older versions of Flutter.
117-
// Should not become part of public API.
118-
@internal
119-
class PlatformDispatcherWrapper {
120-
PlatformDispatcherWrapper(this._dispatcher);
121-
122-
final PlatformDispatcher? _dispatcher;
123-
124-
bool isMultiViewEnabled(SentryFlutterOptions options) {
125-
try {
126-
return ((_dispatcher as dynamic)?.implicitView as FlutterView?) == null;
127-
} on NoSuchMethodError {
128-
// This error is expected on pre 3.10.0 Flutter version
129-
return false;
130-
} catch (exception, stacktrace) {
131-
// This error is neither expected on pre 3.10.0 nor on >= 3.10.0 Flutter versions
132-
options.logger(
133-
SentryLevel.debug,
134-
'An unexpected exception was thrown, please create an issue at https://github.com/getsentry/sentry-dart/issues',
135-
exception: exception,
136-
stackTrace: stacktrace,
137-
);
138-
if (options.automatedTestMode) {
139-
rethrow;
140-
}
141-
return false;
142-
}
143-
}
144-
145-
/// Should not be accessed if [isOnErrorSupported] == false
146-
ErrorCallback? get onError =>
147-
(_dispatcher as dynamic)?.onError as ErrorCallback?;
148-
149-
/// Should not be accessed if [isOnErrorSupported] == false
150-
set onError(ErrorCallback? callback) {
151-
(_dispatcher as dynamic)?.onError = callback;
152-
}
153-
154-
bool isOnErrorSupported(SentryFlutterOptions options) {
155-
try {
156-
onError;
157-
} on NoSuchMethodError {
158-
// This error is expected on pre 3.1 Flutter version
159-
return false;
160-
} catch (exception, stacktrace) {
161-
// This error is neither expected on pre 3.1 nor on >= 3.1 Flutter versions
162-
options.logger(
163-
SentryLevel.debug,
164-
'An unexpected exception was thrown, please create an issue at https://github.com/getsentry/sentry-dart/issues',
165-
exception: exception,
166-
stackTrace: stacktrace,
167-
);
168-
if (options.automatedTestMode) {
169-
rethrow;
170-
}
171-
return false;
172-
}
173-
return true;
174-
}
175-
}

flutter/lib/src/sentry_flutter.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import 'native/sentry_native_binding.dart';
2626
import 'profiling.dart';
2727
import 'renderer/renderer.dart';
2828
import 'replay/integration.dart';
29+
import 'utils/platform_dispatcher_wrapper.dart';
2930
import 'version.dart';
3031
import 'view_hierarchy/view_hierarchy_integration.dart';
3132

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import 'dart:ui';
2+
3+
import 'package:meta/meta.dart';
4+
import 'package:sentry/sentry.dart';
5+
import '../sentry_flutter_options.dart';
6+
7+
/// This class wraps the `this as dynamic` hack in a type-safe manner.
8+
/// It helps to introduce code, which uses newer features from Flutter
9+
/// without breaking Sentry on older versions of Flutter.
10+
///
11+
/// Should not become part of public API.
12+
@internal
13+
class PlatformDispatcherWrapper {
14+
PlatformDispatcherWrapper(this._dispatcher);
15+
16+
final PlatformDispatcher? _dispatcher;
17+
18+
bool isMultiViewEnabled(SentryFlutterOptions options) {
19+
try {
20+
return ((_dispatcher as dynamic)?.implicitView as FlutterView?) == null;
21+
} on NoSuchMethodError {
22+
// This error is expected on pre 3.10.0 Flutter version
23+
return false;
24+
} catch (exception, stacktrace) {
25+
// This error is neither expected on pre 3.10.0 nor on >= 3.10.0 Flutter versions
26+
options.logger(
27+
SentryLevel.debug,
28+
'An unexpected exception was thrown, please create an issue at https://github.com/getsentry/sentry-dart/issues',
29+
exception: exception,
30+
stackTrace: stacktrace,
31+
);
32+
if (options.automatedTestMode) {
33+
rethrow;
34+
}
35+
return false;
36+
}
37+
}
38+
39+
/// Should not be accessed if [isOnErrorSupported] == false
40+
ErrorCallback? get onError =>
41+
(_dispatcher as dynamic)?.onError as ErrorCallback?;
42+
43+
/// Should not be accessed if [isOnErrorSupported] == false
44+
set onError(ErrorCallback? callback) {
45+
(_dispatcher as dynamic)?.onError = callback;
46+
}
47+
48+
bool isOnErrorSupported(SentryFlutterOptions options) {
49+
try {
50+
onError;
51+
} on NoSuchMethodError {
52+
// This error is expected on pre 3.1 Flutter version
53+
return false;
54+
} catch (exception, stacktrace) {
55+
// This error is neither expected on pre 3.1 nor on >= 3.1 Flutter versions
56+
options.logger(
57+
SentryLevel.debug,
58+
'An unexpected exception was thrown, please create an issue at https://github.com/getsentry/sentry-dart/issues',
59+
exception: exception,
60+
stackTrace: stacktrace,
61+
);
62+
if (options.automatedTestMode) {
63+
rethrow;
64+
}
65+
return false;
66+
}
67+
return true;
68+
}
69+
}

flutter/test/integrations/not_initialized_widgets_binding_on_error_integration_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'package:flutter_test/flutter_test.dart';
22
import 'package:mockito/mockito.dart';
33
import 'package:sentry/sentry.dart';
44
import 'package:sentry_flutter/src/integrations/on_error_integration.dart';
5+
import 'package:sentry_flutter/src/utils/platform_dispatcher_wrapper.dart';
56

67
import '../mocks.dart';
78
import '../mocks.mocks.dart';

flutter/test/integrations/on_error_integration_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'package:flutter_test/flutter_test.dart';
22
import 'package:mockito/mockito.dart';
33
import 'package:sentry/sentry.dart';
44
import 'package:sentry_flutter/src/integrations/on_error_integration.dart';
5+
import 'package:sentry_flutter/src/utils/platform_dispatcher_wrapper.dart';
56

67
import '../mocks.dart';
78
import '../mocks.mocks.dart';

0 commit comments

Comments
 (0)