首页 > 解决方案 > 有没有办法在 Flutter 上启动 blob url?

问题描述

我有一个网络应用程序,可根据用户请求查询后端 api 以获取 pdf,然后将其显示在单独的浏览器选项卡中。此代码有效(代码路径 when isFlutterApp=false),如下所示:

let pdf = await Api.getReceiptAsPdf(receipt.id);
var file = new Blob([pdf], {type: 'application/pdf'});
var fileURL = URL.createObjectURL(file);
//fileURL looks like: blob:https://my.example.com/2e48a922-513d-4cb4-8e1f-148d6b7d2640

if (isFlutterApp) sendFlutterNotification(fileURL);
else window.open(fileURL);

Web 应用也可以在 Flutter App 中运行(在 Flutter Web 视图中),然后上面的代码将 fileURL 发送到 Flutter App,而不是调用 window.open。在这种情况下,我使用url_launcher并通过 Flutter 打开相同的 fileUrl:

//fileURL is (e.g.) blob:https://my.example.com/2e48a922-513d-4cb4-8e1f-148d6b7d2640
void _launchURL(u) async =>
      await canLaunch(u) ? await launch(u) : throw 'Could not launch $u'; 

这不起作用,我得到:

-canOpenURL: failed for URL: "blob:https://my.example.com/2e48a922-513d-4cb4-8e1f-148d6b7d2640" - error: "The operation couldn’t be completed. (OSStatus error -10814.)"
[VERBOSE-2:ui_dart_state.cc(186)] Unhandled Exception: Could not launch blob:https://my.example.com/2e48a922-513d-4cb4-8e1f-148d6b7d2640
#0      _MyState._launchURL (package:flutterwrapper/main.dart:173:46) 

到目前为止,我只在 ios 上对此进行了测试,并在 info.plist 中添加了以下条目:

<key>LSApplicationQueriesSchemes</key>
<array>
<string>blob</string>
</array>

这里可能是什么问题?

标签: javascriptflutterdartflutterwebviewpluginurl-launcher

解决方案


推荐阅读