Skip to content

Commit

Permalink
experiment: mask CustomPaint widget
Browse files Browse the repository at this point in the history
  • Loading branch information
vaind committed Oct 10, 2024
1 parent e239c83 commit de2b3df
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
12 changes: 12 additions & 0 deletions flutter/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ Future<void> setupSentry(

options.experimental.replay.sessionSampleRate = 1.0;
options.experimental.replay.onErrorSampleRate = 1.0;
options.experimental.replay.maskAllText = false;

_isIntegrationTest = isIntegrationTest;
if (_isIntegrationTest) {
Expand Down Expand Up @@ -198,6 +199,17 @@ class MainScaffold extends StatelessWidget {
body: SingleChildScrollView(
child: Column(
children: [
const CustomPaint(
child: Center(
child: Text(
'Custom paint',
style: TextStyle(
fontSize: 40.0,
fontWeight: FontWeight.w900,
color: Color.fromARGB(255, 166, 7, 7),
),
),
)),
if (_isIntegrationTest) const IntegrationTestWidget(),
const Center(child: Text('Trigger an action.\n')),
const Padding(
Expand Down
3 changes: 2 additions & 1 deletion flutter/lib/src/replay/widget_filter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ class WidgetFilterItem {
const WidgetFilterItem(this.color, this.bounds);
}

extension on Element {
@internal
extension ElementParentFinder on Element {
Element? get parent {
Element? result;
visitAncestorElements((el) {
Expand Down
18 changes: 18 additions & 0 deletions flutter/lib/src/sentry_replay_options.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:meta/meta.dart';
Expand Down Expand Up @@ -75,6 +76,23 @@ class SentryReplayOptions {
rules
.add(const SentryMaskingCustomRule<Image>(_maskImagesExceptAssets));
}

// Mask CustomPaint, except for DEBUG banner which overlays the whole screen in debug builds.
if (kReleaseMode) {
rules.add(const SentryMaskingConstantRule<CustomPaint>(
SentryMaskingDecision.mask));
} else {
rules.add(SentryMaskingCustomRule<CustomPaint>(
(Element element, CustomPaint widget) {
final parent = element.parent;
if (parent is StatefulElement &&
(parent.widget is Banner) &&
(parent.widget as Banner).message == 'DEBUG') {
return SentryMaskingDecision.continueProcessing;
}
return SentryMaskingDecision.mask;
}));
}
} else {
assert(!maskAssetImages,
"maskAssetImages can't be true if maskAllImages is false");
Expand Down

0 comments on commit de2b3df

Please sign in to comment.