本文介绍了Flutter如何下载本地文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
我正在 flutter 上制作我的投资组合网站,我希望如果有人点击下载 cv 按钮,它会下载到他的设备上。CV 放在 assets 文件夹中。
downloadFile(url) {
AnchorElement anchorElement =
AnchorElement(href: url);
anchorElement.download = "CV";
anchorElement.click();
}
TextButton(
onPressed: () =>
downloadFile("/assets/files/Hassan_Naveed_CV.pdf"),
child: FittedBox(
child: Row(
children: [
Text(
"Download CV",
style: TextStyle(
color: Theme.of(context)
.textTheme
.bodyText1!
.color),
),
const SizedBox(
width: defaultPadding / 2,
),
const Icon(Icons.download, color: Color(0xFF8B8B8D))
],
),
)),
当我点击下载按钮时,它显示下载失败
尝试根据您调用文件的位置检查文件的路径,以及您是否有权访问 pubspec.yml 中的“文件”文件夹。 您的代码对我来说看起来不错,我认为它来自给定的路径。 还要检查文件名中是否没有空格或不需要的字符。
[英文标题]How to download local file in Flutter
声明:本媒体部分图片、文章来源于网络,版权归原作者所有,如有侵权,请联系QQ:330946442删除。