downloadFile method

Future<bool> downloadFile(
  1. Uint8List bytes,
  2. String name,
  3. String type
)

Implementation

Future<bool> downloadFile(Uint8List bytes, String name, String type) async {
  bool _success = false;

  try {
    String _url = Url.createObjectUrlFromBlob(Blob([bytes], type));
    HtmlDocument htmlDocument = document;
    AnchorElement anchor = htmlDocument.createElement('a') as AnchorElement;
    anchor.href = _url;
    anchor.style.display = name;
    anchor.download = name;
    document.body!.children.add(anchor);
    anchor.click();
    document.body!.children.remove(anchor);
    _success = true;
  } catch (e) {
    print(e);
  }
  return _success;
}