问题描述
我正在使用Webview从https://chat.domain.com的Flutter应用程序中加载一个自托管的火箭聊天应用程序。到目前为止,我已经能够正确加载所有内容。现在,我需要检测何时访问了用户的个人资料并显示提示。
例如当user1在消息部分中单击user2时,我应该能够在Flutter应用程序中显示一个警报框。
在Web浏览器中,执行此操作后,URL更改为https://chat.domain.com/direct/token。我正在尝试检测何时打开此URL来执行某些操作,但到目前为止还没有运气。 这是我的代码:
class _WebViewExampleState extends State<WebViewExample> {
String loadUrl = 'https://chat.domain.com';
@override
Widget build(BuildContext context) {
Completer<WebViewController> _controller = Completer<WebViewController>();
return Scaffold(
appBar: AppBar(
title: Text('Webview App'),backgroundColor: Colors.black,),body: Builder(builder: (BuildContext context) {
return Container(
padding: EdgeInsets.only(bottom: 20.0),child: GestureDetector(
child: Expanded(
child: WebView(
initialUrl: loadUrl,javascriptMode: JavascriptMode.unrestricted,onWebViewCreated: (WebViewController webViewController) {
_controller.complete(webViewController);
},navigationDelegate: (NavigationRequest request) {
print('request url: ' + request.url);
//even the above print statement is not getting executed when user performs some action
if (request.url.startsWith('https://chat.domain.com/direct/')) {
String convId = request.url.replaceAll('https://chat.domain.com/direct/','');
//alert here
//URL in the browser changes for this user action
} else if (request.url.startsWith('https://chat.domain.com/api/v1/method.call/sendMessage')) {
//the above url is called when a user sends a message,but this happens in the background.
//URL in the browser remains the same for this user action.
//display some alert
}
print('allowing navigation to $request');
return NavigationDecision.navigate;
},onPageStarted: (String url) {
print('Page started loading: $url');
},onPageFinished: (String url) {
print('Page finished loading: $url');
},gestureNavigationEnabled: true,);
}),);
}
}
我当前正在使用此插件:webview_Flutter:^ 0.3.22 + 1。我已经尝试过其他webview插件,但没有一个能够解决我的问题。
我正在考虑监视来自应用程序的传出URL调用并基于此触发一些操作,但是我不知道该如何实现。
任何帮助将不胜感激。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)