题意

How to Download a File in Flutter web Without Opening a New Tab Using js.context.callMethod('open', [zip, '_blank'])?

如何在 Flutter Web 中使用 `js.context.callMethod('open', [zip, '_blank'])` 下载文件而不打开新标签页?

问题背景:

I'm currently working on a flutter web project where I need to download a file without opening a new tab. I've been experimenting with js.context.callMethod('open', [zip, '_blank']), which does download the file but in a new tab. However, I need the file to be downloaded within the current tab.

我目前正在进行一个 Flutter Web 项目,需要在不打开新标签页的情况下下载文件。我尝试了 `js.context.callMethod('open', [zip, '_blank'])`,这确实下载了文件,但是在新标签页中。然而,我需要在当前标签页中下载文件。

Here's the code snippet I've been using:

这是我一直在使用的代码片段:

using This package, https://pub.dev/packages/js/install

使用这个包:https://pub.dev/packages/js/install

 js.context.callMethod('open', [zip, '_blank']);

问题解决:

`js.context.callMethod('open', [zip, '_self']);`

it's downloading within your tab. use '_self' keyword.

它会在你的标签页内下载。使用`'_self'`关键字。

Logo

开源鸿蒙跨平台开发社区汇聚开发者与厂商,共建“一次开发,多端部署”的开源生态,致力于降低跨端开发门槛,推动万物智联创新。

更多推荐