Skip to content

Commit 9f05645

Browse files
authored
Add attachScreenshotOnlyWhenResumed to options (#1700)
1 parent 64af39c commit 9f05645

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Features
66

77
- Breadcrumbs for database operations ([#1656](https://github.com/getsentry/sentry-dart/pull/1656))
8+
- Add `attachScreenshotOnlyWhenResumed` to options ([#1700](https://github.com/getsentry/sentry-dart/pull/1700))
89

910
### Dependencies
1011

flutter/lib/src/event_processor/screenshot_event_processor.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import '../screenshot/sentry_screenshot_widget.dart';
88
import '../sentry_flutter_options.dart';
99
import 'package:flutter/rendering.dart';
1010
import '../renderer/renderer.dart';
11+
import 'package:flutter/widgets.dart' as widget;
1112

1213
class ScreenshotEventProcessor implements EventProcessor {
1314
final SentryFlutterOptions _options;
@@ -38,6 +39,14 @@ class ScreenshotEventProcessor implements EventProcessor {
3839
return event;
3940
}
4041

42+
if (_options.attachScreenshotOnlyWhenResumed &&
43+
widget.WidgetsBinding.instance.lifecycleState !=
44+
AppLifecycleState.resumed) {
45+
_options.logger(SentryLevel.debug,
46+
'Only attaching screenshots when application state is resumed.');
47+
return event;
48+
}
49+
4150
final bytes = await _createScreenshot();
4251
if (bytes != null) {
4352
hint?.screenshot = SentryAttachment.fromScreenshotData(bytes);

flutter/lib/src/sentry_flutter_options.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ class SentryFlutterOptions extends SentryOptions {
167167
/// The quality of the attached screenshot
168168
SentryScreenshotQuality screenshotQuality = SentryScreenshotQuality.high;
169169

170+
/// Only attach a screenshot when the app is resumed.
171+
bool attachScreenshotOnlyWhenResumed = false;
172+
170173
/// Enable or disable automatic breadcrumbs for User interactions Using [Listener]
171174
///
172175
/// Requires adding the [SentryUserInteractionWidget] to the widget tree.

0 commit comments

Comments
 (0)