Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add multiview helper to make the sentry multiview aware. #2366

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Features

- Add `MultiViewHelper` to make the sentry plugin multiview aware for the web platform and automatically disable `SentryScreenshotWidget`, `SentryUserInteractionWidget` and `WidgetsBindingIntegration` in multi-view applications.([#2366](https://github.com/getsentry/sentry-dart/pull/2366))
martinhaintz marked this conversation as resolved.
Show resolved Hide resolved

### Enhancements

- Cache parsed DSN ([#2365](https://github.com/getsentry/sentry-dart/pull/2365))
Expand Down
16 changes: 13 additions & 3 deletions flutter/lib/src/sentry_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import 'profiling.dart';
import 'renderer/renderer.dart';
import 'span_frame_metrics_collector.dart';
import 'utils/multi_view_helper.dart';
import 'version.dart';
import 'view_hierarchy/view_hierarchy_integration.dart';

Expand Down Expand Up @@ -163,8 +164,16 @@
// Will catch any errors that may occur in the Flutter framework itself.
integrations.add(FlutterErrorIntegration());

// This tracks Flutter application events, such as lifecycle events.
integrations.add(WidgetsBindingIntegration());
if (MultiViewHelper.isMultiViewEnabled()) {
// ignore: invalid_use_of_internal_member
options.logger(

Check warning on line 169 in flutter/lib/src/sentry_flutter.dart

View check run for this annotation

Codecov / codecov/patch

flutter/lib/src/sentry_flutter.dart#L169

Added line #L169 was not covered by tests
SentryLevel.debug,
'`WidgetsBindingIntegration` is not available in multi-view applications.',
);
} else {
// This tracks Flutter application events, such as lifecycle events.
integrations.add(WidgetsBindingIntegration());
martinhaintz marked this conversation as resolved.
Show resolved Hide resolved
}

// The ordering here matters, as we'd like to first start the native integration.
// That allow us to send events to the network and then the Flutter integrations.
Expand All @@ -180,7 +189,8 @@
}

final renderer = options.rendererWrapper.getRenderer();
if (!platformChecker.isWeb || renderer == FlutterRenderer.canvasKit) {
if (!MultiViewHelper.isMultiViewEnabled() && !platformChecker.isWeb ||
martinhaintz marked this conversation as resolved.
Show resolved Hide resolved
renderer == FlutterRenderer.canvasKit) {
integrations.add(ScreenshotIntegration());
}

Expand Down
17 changes: 16 additions & 1 deletion flutter/lib/src/sentry_widget.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/cupertino.dart';
import 'package:meta/meta.dart';
import '../sentry_flutter.dart';
import 'utils/multi_view_helper.dart';

/// Key which is used to identify the [SentryWidget]
@internal
Expand All @@ -11,7 +12,13 @@
class SentryWidget extends StatefulWidget {
final Widget child;

const SentryWidget({super.key, required this.child});
SentryWidget({
super.key,
required this.child,
@internal Hub? hub,
});

final bool _isMultiViewEnabled = MultiViewHelper.isMultiViewEnabled();

@override
_SentryWidgetState createState() => _SentryWidgetState();
Expand All @@ -21,6 +28,14 @@
@override
Widget build(BuildContext context) {
Widget content = widget.child;
if (widget._isMultiViewEnabled) {
// ignore: invalid_use_of_internal_member
Sentry.currentHub.options.logger(

Check warning on line 33 in flutter/lib/src/sentry_widget.dart

View check run for this annotation

Codecov / codecov/patch

flutter/lib/src/sentry_widget.dart#L33

Added line #L33 was not covered by tests
SentryLevel.debug,
'`SentryScreenshotWidget` and `SentryUserInteractionWidget` is not available in multi-view applications.',
);
return content;
}
content = SentryScreenshotWidget(child: content);
content = SentryUserInteractionWidget(child: content);
return Container(
Expand Down
14 changes: 14 additions & 0 deletions flutter/lib/src/utils/multi_view_helper.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import 'dart:ui';
import 'package:meta/meta.dart';

@internal
class MultiViewHelper {
static bool isMultiViewEnabled() {
final dynamic uncheckedImplicitView = PlatformDispatcher.instance;
martinhaintz marked this conversation as resolved.
Show resolved Hide resolved
try {
return null == uncheckedImplicitView.implicitView;
} on NoSuchMethodError catch (_) {

Check warning on line 10 in flutter/lib/src/utils/multi_view_helper.dart

View check run for this annotation

Codecov / codecov/patch

flutter/lib/src/utils/multi_view_helper.dart#L10

Added line #L10 was not covered by tests
return false;
}
}
}
Loading