Spidey Verse
Spidey Verse

Reputation: 1

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. 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 

Upvotes: 0

Views: 5866

Answers (1)

darshan
darshan

Reputation: 4569

controller.reload() will load the current loaded url in the webview.
You should use controller.loadUrl("your_new_url").

More info. about the method here: https://pub.dev/documentation/webview_flutter/latest/webview_flutter/WebViewController/loadUrl.html

Upvotes: 2

Related Questions