我的一个学校项目的目标是用Flutter制作一个网站。该网站应将多个文件显示为一个列表,每个文件都有一个下载按钮。到目前为止一切都很简单。
我的问题是,我无法下载存储在本地或通过下载URL的文件。我已经尝试使用dart HTML插件以及dio包来使其正常工作。不走运。
所以我的问题是:有没有一种方法可以创建一个"onPressed“事件来下载本地文件或通过下载URL?
提前感谢
发布于 2021-01-21 00:59:56
您可以使用this plugin从flutter下载文件
它使用起来非常简单。我正在添加一段代码以集成到您的webview (当它导航到下载URL时使用naviagtionDelegate)
final taskId = await FlutterDownloader.enqueue(
url: 'your download link',
savedDir: 'the path of directory where you want to save downloaded files',
showNotification: true, // show download progress in status bar (for Android)
openFileFromNotification: true, // click on notification to open downloaded file (for Android)
);发布于 2021-01-21 01:10:54
您可以使用Url Launcher包
安装完成后,您可以执行以下操作: onPressed:() => launch('https://www.google.com/file.pdf')
https://stackoverflow.com/questions/65813082
复制相似问题