downloadTicket static method
Implementation
static Future<void> downloadTicket(
String ticketUrl,
String label,
String fileName,
) async {
try {
final response = await Dio().get(ticketUrl,
options: Options(responseType: ResponseType.bytes));
if (response.statusCode == 200) {
final blob = html.Blob([response.data]);
final url = html.Url.createObjectUrl(blob);
final anchor = html.AnchorElement(href: url);
anchor.download = fileName;
anchor.click();
html.Url.revokeObjectUrl(url);
} else {
log('Failed to download $label: Status code ${response.statusCode}');
CustomFlashWidget.showFlashMessage(
type: FlashType.error,
title: "Error",
message: '$label Download Failed, Please contact customer support',
);
}
} catch (e) {
log('Failed to download $label: $e');
}
}