Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can i download the file #258

Open
prasanmoonraft opened this issue Jun 18, 2024 · 3 comments
Open

How can i download the file #258

prasanmoonraft opened this issue Jun 18, 2024 · 3 comments
Labels
type-question A question about expected behavior or functionality

Comments

@prasanmoonraft
Copy link

prasanmoonraft commented Jun 18, 2024

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 srujzs added the type-question A question about expected behavior or functionality label Jun 18, 2024
@srujzs
Copy link
Contributor

srujzs commented Jun 18, 2024

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
Copy link
Author

prasanmoonraft commented Jun 19, 2024

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
Copy link
Contributor

srujzs commented Jun 25, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-question A question about expected behavior or functionality
Projects
None yet
Development

No branches or pull requests

2 participants