【发布时间】:2026-01-08 18:15:02
【问题描述】:
我的一个学校项目的目标是用 Flutter 制作一个网站。该站点应将多个文件显示为一个列表,其中每个文件都有一个下载按钮。到目前为止一切都很简单。
我的问题是我无法下载存储在本地或通过下载 URL 的文件。我尝试使用 dart HTML 插件和 dio 包来让它工作。没有运气。
所以我的问题是:有没有办法让“onPressed”事件下载本地文件或通过下载 URL?
提前致谢
【问题讨论】:
我的一个学校项目的目标是用 Flutter 制作一个网站。该站点应将多个文件显示为一个列表,其中每个文件都有一个下载按钮。到目前为止一切都很简单。
我的问题是我无法下载存储在本地或通过下载 URL 的文件。我尝试使用 dart HTML 插件和 dio 包来让它工作。没有运气。
所以我的问题是:有没有办法让“onPressed”事件下载本地文件或通过下载 URL?
提前致谢
【问题讨论】:
你可以使用this plugin从flutter下载文件
使用起来非常简单。我正在添加一个 sn-p 代码以集成到您的 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)
);
【讨论】:
void downloadFile() async { WidgetsFlutterBinding.ensureInitialized(); await FlutterDownloader.initialize(debug: true); final taskId = await FlutterDownloader.enqueue(url:"https://groups.csail.mit.edu/graphics/classes/6.837/F03/models/teapot.obj",savedDir: "path to my downloads folder"); } 这会引发 UnimplementedError
你可以使用包Url Launcher
安装后,您可以: onPressed: () => 启动('https://www.google.com/file.pdf')
【讨论】: