diff --git a/flutter/lib/src/native/factory.dart b/flutter/lib/src/native/factory.dart new file mode 100644 index 0000000000..981e1d6ead --- /dev/null +++ b/flutter/lib/src/native/factory.dart @@ -0,0 +1 @@ +export 'factory_real.dart' if (dart.library.html) 'factory_web.dart'; diff --git a/flutter/lib/src/native/factory_real.dart b/flutter/lib/src/native/factory_real.dart new file mode 100644 index 0000000000..3c918b7be7 --- /dev/null +++ b/flutter/lib/src/native/factory_real.dart @@ -0,0 +1,14 @@ +import 'package:flutter/services.dart'; + +import '../../sentry_flutter.dart'; +import 'cocoa/sentry_native_cocoa.dart'; +import 'sentry_native_binding.dart'; +import 'sentry_native_channel.dart'; + +SentryNativeBinding createBinding(PlatformChecker pc, MethodChannel channel) { + if (pc.platform.isIOS || pc.platform.isMacOS) { + return SentryNativeCocoa(channel); + } else { + return SentryNativeChannel(channel); + } +} diff --git a/flutter/lib/src/native/factory_web.dart b/flutter/lib/src/native/factory_web.dart new file mode 100644 index 0000000000..8038ea9780 --- /dev/null +++ b/flutter/lib/src/native/factory_web.dart @@ -0,0 +1,9 @@ +import 'package:flutter/services.dart'; + +import '../../sentry_flutter.dart'; +import 'sentry_native_binding.dart'; + +// This isn't actually called, see SentryFlutter.init() +SentryNativeBinding createBinding(PlatformChecker pc, MethodChannel channel) { + throw UnsupportedError("Native binding is not supported on this platform."); +} diff --git a/flutter/lib/src/sentry_flutter.dart b/flutter/lib/src/sentry_flutter.dart index e11537c4ee..59b42266c7 100644 --- a/flutter/lib/src/sentry_flutter.dart +++ b/flutter/lib/src/sentry_flutter.dart @@ -10,13 +10,11 @@ import 'event_processor/android_platform_exception_event_processor.dart'; import 'event_processor/flutter_exception_event_processor.dart'; import 'event_processor/platform_exception_event_processor.dart'; import 'integrations/screenshot_integration.dart'; -import 'native/cocoa/sentry_native_cocoa.dart'; +import 'native/factory.dart'; import 'native/native_scope_observer.dart'; -import 'native/sentry_native_channel.dart'; import 'profiling.dart'; import 'renderer/renderer.dart'; import 'native/sentry_native.dart'; -import 'native/sentry_native_binding.dart'; import 'integrations/integrations.dart'; import 'event_processor/flutter_enricher_event_processor.dart'; @@ -51,16 +49,7 @@ mixin SentryFlutter { } if (flutterOptions.platformChecker.hasNativeIntegration) { - late final SentryNativeBinding binding; - - // Set a default native channel to the singleton SentryNative instance. - if (flutterOptions.platformChecker.platform.isIOS || - flutterOptions.platformChecker.platform.isMacOS) { - binding = SentryNativeCocoa(channel); - } else { - binding = SentryNativeChannel(channel); - } - + final binding = createBinding(flutterOptions.platformChecker, channel); _native = SentryNative(flutterOptions, binding); }