downloadTicket static method

Future<void> downloadTicket(
  1. String ticketUrl,
  2. String label,
  3. String fileName
)

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');
  }
}