handle method
Method called when report has been accepted by user
Implementation
@override
Future<bool> handle(Report report, BuildContext? context) async {
try {
_printLog('Logging to sentry...');
final tags = <String, dynamic>{};
if (enableApplicationParameters) {
tags.addAll(report.applicationParameters);
}
if (enableDeviceParameters) {
tags.addAll(report.deviceParameters);
}
if (enableCustomParameters) {
tags.addAll(report.customParameters);
}
final event = buildEvent(report, tags);
// If we have a screenshot and we're not in web, then upload screenshot
// to Sentry. Screenshot isn't supported in web (not by Sentry or catcher)
// and the code relies on File from dart:io that does not work in web
// either because we do not have access to the file system in web.
SentryAttachment? screenshotAttachment;
try {
if (report.screenshot != null && !kIsWeb) {
final bytes = await report.screenshot!.readAsBytes();
screenshotAttachment = SentryAttachment.fromScreenshotData(bytes);
_printLog('Created screenshot attachment');
}
} catch (exception, stackTrace) {
_printLog('Failed to read screenshot data: $exception $stackTrace');
}
await sentryClient.captureEvent(
event,
stackTrace: report.stackTrace,
hint: screenshotAttachment != null
? Hint.withScreenshot(screenshotAttachment)
: null,
);
_printLog('Logged to sentry!');
return true;
} catch (exception, stackTrace) {
_printLog('Failed to send sentry event: $exception $stackTrace');
return false;
}
}