downloadBlob function

void downloadBlob(
  1. Blob blob,
  2. String fileName
)

Downloads blob of type mimeType, saving a file with fileName.

Implementation

void downloadBlob(Blob blob, String fileName) {
  var fileLink = AnchorElement();
  fileLink.style.display = 'none';

  if (isNotEmptyObject(fileName)) fileLink.download = fileName;
  // ignore: unsafe_html
  fileLink.href = Url.createObjectUrlFromBlob(blob);

  fileLink.onClick.listen((event) {
    fileLink.remove();
  });

  document.body!.append(fileLink);

  fileLink.click();
}