diff --git a/CHANGELOG.md b/CHANGELOG.md index 84845a06df..20cc2eeb9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Features - Breadcrumbs for database operations ([#1656](https://github.com/getsentry/sentry-dart/pull/1656)) +- Add `attachScreenshotOnlyWhenResumed` to options ([#1700](https://github.com/getsentry/sentry-dart/pull/1700)) ### Dependencies diff --git a/flutter/lib/src/event_processor/screenshot_event_processor.dart b/flutter/lib/src/event_processor/screenshot_event_processor.dart index b60f4faefa..bb1157c1de 100644 --- a/flutter/lib/src/event_processor/screenshot_event_processor.dart +++ b/flutter/lib/src/event_processor/screenshot_event_processor.dart @@ -8,6 +8,7 @@ import '../screenshot/sentry_screenshot_widget.dart'; import '../sentry_flutter_options.dart'; import 'package:flutter/rendering.dart'; import '../renderer/renderer.dart'; +import 'package:flutter/widgets.dart' as widget; class ScreenshotEventProcessor implements EventProcessor { final SentryFlutterOptions _options; @@ -38,6 +39,14 @@ class ScreenshotEventProcessor implements EventProcessor { return event; } + if (_options.attachScreenshotOnlyWhenResumed && + widget.WidgetsBinding.instance.lifecycleState != + AppLifecycleState.resumed) { + _options.logger(SentryLevel.debug, + 'Only attaching screenshots when application state is resumed.'); + return event; + } + final bytes = await _createScreenshot(); if (bytes != null) { hint?.screenshot = SentryAttachment.fromScreenshotData(bytes); diff --git a/flutter/lib/src/sentry_flutter_options.dart b/flutter/lib/src/sentry_flutter_options.dart index 5f85e85cb0..7a82f3b53f 100644 --- a/flutter/lib/src/sentry_flutter_options.dart +++ b/flutter/lib/src/sentry_flutter_options.dart @@ -167,6 +167,9 @@ class SentryFlutterOptions extends SentryOptions { /// The quality of the attached screenshot SentryScreenshotQuality screenshotQuality = SentryScreenshotQuality.high; + /// Only attach a screenshot when the app is resumed. + bool attachScreenshotOnlyWhenResumed = false; + /// Enable or disable automatic breadcrumbs for User interactions Using [Listener] /// /// Requires adding the [SentryUserInteractionWidget] to the widget tree.