1
1
import 'dart:async' ;
2
+ import 'dart:ui' ;
2
3
3
4
import 'package:flutter/scheduler.dart' ;
4
5
import 'package:flutter/services.dart' ;
5
6
import 'package:meta/meta.dart' ;
6
7
import 'package:package_info_plus/package_info_plus.dart' ;
7
- import 'package:sentry/sentry .dart' ;
8
+ import '../sentry_flutter .dart' ;
8
9
import 'event_processor/android_platform_exception_event_processor.dart' ;
9
10
import 'native_scope_observer.dart' ;
10
11
import 'sentry_native.dart' ;
@@ -13,9 +14,7 @@ import 'sentry_native_channel.dart';
13
14
import 'event_processor/flutter_enricher_event_processor.dart' ;
14
15
import 'integrations/debug_print_integration.dart' ;
15
16
import 'integrations/native_app_start_integration.dart' ;
16
- import 'sentry_flutter_options.dart' ;
17
17
18
- import 'default_integrations.dart' ;
19
18
import 'file_system_transport.dart' ;
20
19
21
20
import 'version.dart' ;
@@ -45,27 +44,28 @@ mixin SentryFlutter {
45
44
final native = SentryNative ();
46
45
native .setNativeChannel (nativeChannel);
47
46
47
+ final platformDispatcher = PlatformDispatcher .instance;
48
+ final wrapper = PlatformDispatcherWrapper (platformDispatcher);
49
+ final isOnErrorSupported = wrapper.isOnErrorSupported (flutterOptions);
50
+
48
51
// first step is to install the native integration and set default values,
49
52
// so we are able to capture future errors.
50
53
final defaultIntegrations = _createDefaultIntegrations (
51
- packageLoader,
52
- channel,
53
- flutterOptions,
54
- );
54
+ packageLoader, channel, flutterOptions, isOnErrorSupported);
55
55
for (final defaultIntegration in defaultIntegrations) {
56
56
flutterOptions.addIntegration (defaultIntegration);
57
57
}
58
58
59
59
await _initDefaultValues (flutterOptions, channel);
60
60
61
- await Sentry .init (
62
- (options) async {
63
- await optionsConfiguration (options as SentryFlutterOptions );
64
- } ,
65
- appRunner : appRunner,
66
- // ignore: invalid_use_of_internal_member
67
- options : flutterOptions,
68
- );
61
+ await Sentry .init ((options) async {
62
+ await optionsConfiguration (options as SentryFlutterOptions );
63
+ },
64
+ appRunner : appRunner ,
65
+ // ignore: invalid_use_of_internal_member
66
+ options : flutterOptions,
67
+ // ignore: invalid_use_of_internal_member
68
+ callAppRunnerInRunZonedGuarded : ! isOnErrorSupported );
69
69
}
70
70
71
71
static Future <void > _initDefaultValues (
@@ -96,6 +96,7 @@ mixin SentryFlutter {
96
96
PackageLoader packageLoader,
97
97
MethodChannel channel,
98
98
SentryFlutterOptions options,
99
+ bool isOnErrorSupported,
99
100
) {
100
101
final integrations = < Integration > [];
101
102
final platformChecker = options.platformChecker;
@@ -104,6 +105,11 @@ mixin SentryFlutter {
104
105
// Will call WidgetsFlutterBinding.ensureInitialized() before all other integrations.
105
106
integrations.add (WidgetsFlutterBindingIntegration ());
106
107
108
+ // Use PlatformDispatcher.onError instead of zones.
109
+ if (isOnErrorSupported) {
110
+ integrations.add (OnErrorIntegration ());
111
+ }
112
+
107
113
// Will catch any errors that may occur in the Flutter framework itself.
108
114
integrations.add (FlutterErrorIntegration ());
109
115
0 commit comments