How is shouldOverrideUrl called


I’m totally new to android development.
Recently I’m asked to investigate something about webview loading for our app which is written by flutter, and used flutter_webview_plugin.

After I version up flutter_webview_plugin, I find there are some changes.

And there is the code in flutter_webview_plugin

    public void onPageStarted(WebView view, String url, Bitmap favicon) {
        super.onPageStarted(view, url, favicon);
        Map<String, Object> data = new HashMap<>();
        data.put("url", url);
        data.put("type", "startLoad");"onState", data);

    public void onPageFinished(WebView view, String url) {
        super.onPageFinished(view, url);
        Map<String, Object> data = new HashMap<>();
        data.put("url", url);"onUrlChanged", data);

        data.put("type", "finishLoad");"onState", data);


    public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
        // returning true causes the current WebView to abort loading the URL,
        // while returning false causes the WebView to continue loading the URL as usual.
        String url = request.getUrl().toString();
        boolean isInvalid = checkInvalidUrl(url);
        Map<String, Object> data = new HashMap<>();
        data.put("url", url);
        data.put("type", isInvalid ? "abortLoad" : "shouldStart");"onState", data);
        return isInvalid;

I tried to search everywhere by using shouldOverrideUrlLoading, onPageStarted,onPageFinished, but can’t find where they are called.
I think they should be used by like:

BrowserClient webViewClient;



something like above. But I can’t find anything.


The WebView calls these methods itself when a page is supposed to be loaded.

So let us say the WebView is trying to load, the method shouldOverrideUrlLoading will get a call with the web address passed in to the request argument.

You can return true or false to tell the WebView whether it should load the url, or if it should stop it.

A common use case is to prevent the user from navigating away from a specific webpage in a in app browser.

Hope this helps!!

Answered By – SteelToe

Answer Checked By – Marie Seifert (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *