dart-lang / web

Lightweight browser API bindings built around JS static interop.
https://pub.dev/packages/web
BSD 3-Clause "New" or "Revised" License
135 stars 23 forks source link

How can i download the file #258

Open prasanmoonraft opened 5 months ago

prasanmoonraft commented 5 months ago

with import 'dart:html' as html; was using this html.AnchorElement(href: url) // Set the download attribute to file name. ..setAttribute("download", "") // Trigger a click event on the anchor element to initiate the download. ..click(); and it's was working absolutely fine url: https://pdfobject.com/pdf/sample.pdf

how it'll work with web package

srujzs commented 5 months ago

It's useful to look at the dart:html source code here to compare. The code should be similar. The only difference is that the AnchorElement constructor in dart:html took in an href that it explicitly set (well that and the rename of the type).

import 'package:web/web.dart' as web;
...
var anchorElement = web.HTMLAnchorElement()
  ..href = url
  ..setAttribute('download', '')
  ..click();
prasanmoonraft commented 5 months ago

For Android build it's failing how we can use this as web and don't fail the android build The unavailable library 'dart:js_interop' is imported through these packages:

srujzs commented 4 months ago

I'll need a bit more information, but if you're compiling to native, dart:js_interop is unavailable as it's not a web platform.