Issue
I have been looking around for a webview plugin in flutter that can detect when the url changes, but didn't find a match? The reason I am trying to detect a url change is because I want to change a bool variable to true when changed, which will then change the color of a appbar, is this possible?Are there any simple/easy examples out there that can achieve what i'm looking for? Thanks for any help in advance!
Solution
You can do with navigationDelegate:
WebView(
initialUrl: yourInitialUrl,
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController webViewController) {
_controller.complete(webViewController);
},
navigationDelegate: (NavigationRequest request) {
if(request.url.startsWith(urlSearched)) {
//You can do anything
//Prevent that url works
return NavigationDecision.prevent;
}
//Any other url works
return NavigationDecision.navigate;
},
)
Answered By - Álvaro Agüero
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.