handle method
Method called when report has been accepted by user
Implementation
@override
Future<bool> handle(Report report, BuildContext? context) async {
try {
if (!(await Catcher2Utils.isInternetConnectionAvailable())) {
_printLog('No internet connection available');
return false;
}
var message = '';
if (customMessageBuilder != null) {
message = await customMessageBuilder!(report);
} else {
message = _buildMessage(report);
}
final screenshot = report.screenshot;
final data = <String, dynamic>{
'text': message,
'channel': channel,
'username': username,
'icon_emoji': iconEmoji,
};
_printLog('Sending request to Slack server...');
if (screenshot != null) {
data.addAll(
await _tryUploadScreenshot(screenshot: screenshot),
);
}
final response = await _dio.post<dynamic>(
webhookUrl,
data: json.encode(data),
options: Options(contentType: Headers.formUrlEncodedContentType),
);
_printLog(
'Server responded with code: ${response.statusCode} and '
'message: ${response.statusMessage}',
);
return response.ok;
} catch (exception) {
_printLog('Failed to send slack message: $exception');
return false;
}
}