简体   繁体   English

导航到 flutter WebView 中的不同 URL

[英]Navigate to different URL in flutter WebView

I am trying to update the url or somehow navigate to another page if the url has "intent" which automatically comes when I navigate to any movie on netflix.我正在尝试更新 url 或以某种方式导航到另一个页面,如果 url 具有“意图”,当我导航到 netflix 上的任何电影时会自动出现。 Here is the code-这是代码-

          navigationDelegate: (NavigationRequest request) {
            if (request.url.substring(0, 6) == "intent") {
              print("its intent");
              setState(() {
                currentUrl = "https${request.url.substring(6)}";
                print(currentUrl);
              });
            } else {
              print("Still way ahead");
            }
            //I want to navigate to currentUrl but Navigate.Decision.navigate navigates to request.url
            return NavigationDecision.navigate;
          },
          
          initialUrl: currentUrl,
          javascriptMode: JavascriptMode.unrestricted,)```


Here in the navigationDelegate I want to update the url but since request.url is a final,
 I cannot do so......Is there any other way I can navigate to currentUrl


I also tried another method-

onPageFinished: (url) {
            if (url.substring(0, 6) == "intent") {
              print("its intent");
          setState(() {
                currentUrl = "https://www.google.com/";
              });
              controller.reload();
            } else {
              print("Still way ahead");

            }
          }

The problem is that controller.reload is just going back to the previous url 

controller.reload() will load the current loaded url in the webview. controller.reload()将在 webview 中加载当前加载的 url。
You should use controller.loadUrl("your_new_url") .您应该使用controller.loadUrl("your_new_url")

More info.更多信息。 about the method here: https://pub.dev/documentation/webview_flutter/latest/webview_flutter/WebViewController/loadUrl.html关于这里的方法: https://pub.dev/documentation/webview_flutter/latest/webview_flutter/WebViewController/loadUrl.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM