首页 > 解决方案 > 从 url 下载文件,保存到手机存储

问题描述

我正在做一个项目,一旦点击按钮,我就需要从 URL 下载文件,并将其存储到手机存储中(可能是下载文件夹)。

关于如何做到这一点的任何想法?正在下载的文件也不总是相同的,可以是从图像到 pdf 的任何内容。

标签: filedownloadflutter

解决方案


使用https://pub.dartlang.org/packages/flutter_downloader。不要忘记进行平台配置。

基本上,这就是你应该如何使用这个包。链接中有一个详细的长示例。

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)
);

编辑:有人说上面的包维护得很好。试试这个 https://pub.dev/packages/flowder


推荐阅读