downloadToUser method

Future<void> downloadToUser(
  1. String filename,
  2. Uint8List data
)

Download a file to the user's downloads folder using browser download This is the web equivalent of saving to a file path

Implementation

Future<void> downloadToUser(String filename, Uint8List data) async {
  final blob = Blob([data.toJS].toJS);
  final url = URL.createObjectURL(blob);
  final anchor = document.createElement('a') as HTMLAnchorElement;
  anchor.href = url;
  anchor.download = filename;
  anchor.style.display = 'none';

  document.body!.appendChild(anchor);
  anchor.click();
  anchor.remove();
  URL.revokeObjectURL(url);
}