dart-lang / web

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

How can i download the file #258

Open prasanmoonraft opened 2 weeks ago

prasanmoonraft commented 2 weeks 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 2 weeks 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 2 weeks 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 1 week 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.