我在我的颤振应用程序中使用 webview_flutter 插件。当 url 更改时,如何添加 header 参数以及如何以及如何跟踪 url 更改?那是我的代码。我尝试在 navigationDelegate 中使用 loadurl,但它不起作用。我怎样才能做到这一点?请帮忙
String URL = 'https://...../login-app?authkey=${globals.authkey}&test=1';
WebViewController _webViewController;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: new AppBar(),
body: WebView(
// initialUrl: 'https://...../login-app?authkey=${globals.authkey}',
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController webViewController) {
_controller.complete(webViewController);
webViewController.loadUrl(URL,headers: {"SB-app": "iphone"},);
},
navigationDelegate: (NavigationRequest request) async {
print('allowing navigation to $request');
if(request.url.contains('driver/chat') || request.url.contains('driver/on-map') || request.url.contains('driver/passanger-form') || request.url.contains('driver/login')) {
_webViewController.loadUrl(request.url, headers: {"SB-app": "iphone"});
}
return NavigationDecision.navigate;
},
onPageStarted: (String url) async {
print('Page started loading: $url');
},
onPageFinished: (String url) async {
print('Page finished loading: $url');
},