从url下载文件,保存到手机存储

从url下载文件,保存到手机存储

问题描述:

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

I'm working on a project, that requires me to download a file from URL, once a button is tapped, and store it to phone storage (probably downloads folder).

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

Any ideas on how to do this? The file that is being downloaded is also not always the same and can be anything from an image to a pdf.

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

Use https://pub.dartlang.org/packages/flutter_downloader. Don't forget to do platform configurations.

基本上,这就是您应该如何使用该软件包.链接中有详细的长示例.

Basically, this is how you should use the package. There is a detailed long example in the link.

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

Some people said the package on top is to well maintained. Try this one https://pub.dev/packages/flowder