flutter - 在AppWebview中颤动:对点击pdf链接做出反应
问题描述
我正在尝试在颤振中使用 InAppWebview 插件,效果很好,但是当我单击 pdf 链接时,它什么也不做。
尝试一下,只需点击谷歌搜索中的第一个或第二个链接。
也不shouldOverrideUrlLoading
或onDownloadStart
关于如何显示或如何拦截它的任何想法?
class WebViewWidget extends StatefulWidget {
final String url;
WebViewWidget(this.url);
@override
_WebViewWidgetState createState() => _WebViewWidgetState();
}
class _WebViewWidgetState extends State<WebViewWidget> {
final Completer<InAppWebViewController> _controller =
Completer<InAppWebViewController>();
final InAppWebViewGroupOptions _options = InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(
useShouldOverrideUrlLoading: true,
mediaPlaybackRequiresUserGesture: false,
javaScriptEnabled: true,
),
android: AndroidInAppWebViewOptions(
useHybridComposition: true,
loadWithOverviewMode: true,
useWideViewPort: false,
builtInZoomControls: false,
domStorageEnabled: true,
supportMultipleWindows: true,
),
);
@override
Widget build(BuildContext context) {
return Scaffold(
body: Builder(builder: (BuildContext context) {
return InAppWebView(
initialUrlRequest: URLRequest(url: Uri.parse("https://www.google.com/search?client=firefox-b-d&q=pdf+example")),
initialOptions: _options,
shouldOverrideUrlLoading: (controller, action) {
print("override");
return Future.value(NavigationActionPolicy.ALLOW);
},
onWebViewCreated: (webViewController) {
_controller.complete(webViewController);
},
onDownloadStart: (controller, uri) {
print("download");
},
);
}),
);
}
}
解决方案
要onDownloadStart
被调用useOnDownloadStart: true
必须设置为 on crossPlatform: InAppWebViewOptions()
。一旦完成,回调就会被正确调用。
推荐阅读
- regex - 如何在 Raku 中将包含捕获组括号的字符串插入为正则表达式?
- ios - 初始化后不会调用 onAppear 吗?
- reactjs - React - 渲染的钩子比上一次渲染时更多
- azure - Azure 函数中的 Azure 应用程序配置
- javascript - Safari 和 iOS 设备上的 jQuery AJAX 错误
- python - 将 python 应用程序与 dynamoDB 连接
- list - 在方案中编辑嵌套列表
- php - Symfony 5:在 null 上调用成员函数 encodePassword()
- github - 使用另一个存储库的 github 操作工作流文件
- html - 如何使用 html 在我的网站上删除“恢复安全”警告?