Flutter url_launcher 下载pdf文件而不是在浏览器中打开它
我正在使用url_launcher: ^5.7.5,当我通过启动功能中的PDF URL时,它会继续下载PDF,而不是在我的浏览器上打开它,
onTap: () async {
url="http://3.65.45.149/uploads/store/vendor_report/vendor_pickup_report_257.pdf";
if (await canLaunch(url)){
await launch(url,
headers: { "Content-Type":"application/pdf",
"Content-Disposition":"inline"}, );
print("browser url");
print(url);
}
else
// can't launch url, there is some error
throw "Could not launch $url";
},
I'm using url_launcher: ^5.7.5 and when i'm passing a pdf url in the launch function it it keeps downloading the pdf instead of opening it on my browser,
onTap: () async {
url="http://3.65.45.149/uploads/store/vendor_report/vendor_pickup_report_257.pdf";
if (await canLaunch(url)){
await launch(url,
headers: { "Content-Type":"application/pdf",
"Content-Disposition":"inline"}, );
print("browser url");
print(url);
}
else
// can't launch url, there is some error
throw "Could not launch $url";
},
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在新版本的 URl_laucher 中,您需要手动指定启动模式,如下所示:
In the new version of
URl_laucher
you need to manually specify the launch mode like this:更新了
url_launcher
flutter软件包的较新版本。启动
和canlaunch
函数已弃用。您可以简化代码并在紧凑的功能中提取它:
Updated for the newer versions of the
url_launcher
flutter package. Thelaunch
andcanLaunch
functions are deprecated.You can simplify your code and extract it in a compact function:
我相信在这种情况下,最好使用 webview_flutter: ^3.0.2 而不是 laucher ,希望对您有帮助!
I believe that in this case, would be better you be using webview_flutter: ^3.0.2 instead of laucher, hope that helps you!
我尝试了所有方法,但对我有用的是,不要直接启动文件 URL,而是将 Google Drive 嵌入链接附加到它
url = 'https://docs.google.com/gview?embedded=true&url=${ fileUrl}'
对于您的情况 fileUrl = 'http://3.65.45.149/uploads/store/vendor_report/vendor_pickup_report_257.pdf'
I tried everything but what worked for me was instead of launching your file URL directly, attach Google Drive embed link to it
url = 'https://docs.google.com/gview?embedded=true&url=${fileUrl}'
For your case fileUrl = 'http://3.65.45.149/uploads/store/vendor_report/vendor_pickup_report_257.pdf'