Search code examples
flutterdartwebviewwkwebview

Flutter WebView is not updating URL correctly for some sites


I am using the flutter_webView in my app like this:

  WebView(
    initialUrl: 'https://www.mediamarkt.de/',
    javascriptMode: JavascriptMode.unrestricted,
    onWebViewCreated: (WebViewController webViewController) {
      _controller = webViewController;
    },
    onPageStarted: (String url) {
      setState(() {
        _isLoading = true;
      });
    },
    onPageFinished: (String url) {
      setState(() {
        _currentUrl = url;
        _isLoading = false;
        print('onagePageFinished: $_currentUrl');
      });
    },
  ),

Problem:

As you can see, I am updating the url everytime onPageFinished is called. That works for most of the time. However when navigating https://www.mediamarkt.de/ nothing is called. The URL is always the same.

What am I missing here? Let me know if you need any more information!


Solution

  • so the solution was rather simple:

    final String? url = await _controller.currentUrl();
    

    not quite sure why onPageFinished is not always refreshing correctly but with the above code everything is working just as expected.