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 6 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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Features

- add multiview helper to make the sentry widget multiview aware for the web platform ([#2366](https://github.com/getsentry/sentry-dart/pull/2366))

## 8.10.0-beta.2

### Fixes
Expand Down
12 changes: 11 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/multi_view_helper.dart';

/// Key which is used to identify the [SentryWidget]
@internal
Expand All @@ -11,7 +12,13 @@ final sentryWidgetGlobalKey = GlobalKey(debugLabel: 'sentry_widget');
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,9 @@ class _SentryWidgetState extends State<SentryWidget> {
@override
Widget build(BuildContext context) {
Widget content = widget.child;
if (widget._isMultiViewEnabled) {
return content;
}
content = SentryScreenshotWidget(child: content);
content = SentryUserInteractionWidget(child: content);
return Container(
Expand Down
16 changes: 16 additions & 0 deletions flutter/lib/src/utils/multi_view/html_multi_view_helper.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'dart:ui';
import 'multi_view_helper.dart';

MultiViewHelper multiViewHelper() => HtmlMultiViewHelper();

class HtmlMultiViewHelper implements MultiViewHelper {
@override
bool isMultiViewEnabled() {
martinhaintz marked this conversation as resolved.
Show resolved Hide resolved
final dynamic uncheckedImplicitView = PlatformDispatcher.instance;
try {
return null == uncheckedImplicitView.implicitView;
} on NoSuchMethodError catch (_) {
return false;
}
}
}
10 changes: 10 additions & 0 deletions flutter/lib/src/utils/multi_view/io_multi_view_helper.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import 'multi_view_helper.dart';

MultiViewHelper multiViewHelper() => IoMultiViewHelper();

class IoMultiViewHelper implements MultiViewHelper {
@override
bool isMultiViewEnabled() {
return false;
}
}
8 changes: 8 additions & 0 deletions flutter/lib/src/utils/multi_view/multi_view_helper.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import 'io_multi_view_helper.dart'
if (dart.library.html) 'html_multi_view_helper.dart'
if (dart.library.js_interop) 'web_multi_view_helper.dart';

abstract class MultiViewHelper {
bool isMultiViewEnabled();
factory MultiViewHelper() => multiViewHelper();
}
16 changes: 16 additions & 0 deletions flutter/lib/src/utils/multi_view/web_multi_view_helper.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'dart:ui';
import 'multi_view_helper.dart';

MultiViewHelper multiViewHelper() => WebMultiViewHelper();

class WebMultiViewHelper implements MultiViewHelper {
@override
bool isMultiViewEnabled() {
final dynamic uncheckedImplicitView = PlatformDispatcher.instance;
try {
return null == uncheckedImplicitView.implicitView;
} on NoSuchMethodError catch (_) {
return false;
}
}
}
Loading