captureScreenshot static method

Future<SentryAttachment?> captureScreenshot()

Uses SentryScreenshotWidget to capture the current screen as a SentryAttachment.

Implementation

static Future<SentryAttachment?> captureScreenshot() async {
  // ignore: invalid_use_of_internal_member
  final options = Sentry.currentHub.options;
  if (!SentryScreenshotWidget.isMounted) {
    options.logger(
      SentryLevel.debug,
      'SentryScreenshotWidget could not be found in the widget tree.',
    );
    return null;
  }
  final processors =
      options.eventProcessors.whereType<ScreenshotEventProcessor>();
  if (processors.isEmpty) {
    options.logger(
      SentryLevel.debug,
      'ScreenshotEventProcessor could not be found.',
    );
    return null;
  }
  final processor = processors.first;
  final bytes = await processor.createScreenshot();
  if (bytes != null) {
    return SentryAttachment.fromScreenshotData(bytes);
  } else {
    return null;
  }
}