downloadFile function

void downloadFile(
  1. String url,
  2. String fileName
)

Implementation

void downloadFile(String url, String fileName) {
  if (kIsWeb) {
    final anchorElement = web.HTMLAnchorElement()
      ..href = url
      ..setAttribute('download', fileName)
      ..target = '_blank'
      ..download = fileName;
    web.document.body?.appendChild(anchorElement);
    anchorElement
      ..click()
      ..remove();
  }
}