Description
With dart:html i used this to download a file,
`static void _downloadFile(List bytes, String fileNameWithExtension) {
final html.Blob blob = html.Blob([bytes]);
final String url = html.Url.createObjectUrlFromBlob(blob);
final html.AnchorElement anchor = html.document.createElement('a') as html.AnchorElement
..href = url
..style.display = 'none'
..download = fileNameWithExtension;
html.document.body!.children.add(anchor);
// download
anchor.click();
// cleanup
html.document.body!.children.remove(anchor);
html.Url.revokeObjectUrl(url);
}`
and work fine
now I try to refactor to use the new package web
`static void _downloadFile(List bytes, String fileNameWithExtension) {
final web.Blob blob = web.Blob(bytes.map((int byte) => byte.toJS).toList().toJS);
final String url = web.URL.createObjectURL(blob.toJSBox);
final web.HTMLAnchorElement anchor = web.document.createElement('a') as web.HTMLAnchorElement
..href = url
..style.display = 'none'
..download = fileNameWithExtension;
// Insert new elements in the DOM:
web.document.body!.appendChild(anchor);
// download
anchor.click();
// cleanup
web.document.body!.removeChild(anchor);
web.URL.revokeObjectURL(url);
}`
but it doesn't work
Error: Attempting to box non-Dart object.