Get current URL in webview

2,051

Is it enough for your reload button to use Future<Null> reload();? This seems to reload the current url. So you don't have to set the url explicit.

You have to change the call of the function to

onPressed: () => flutterWebviewPlugin.reload(), // this is reloading the url that was provided to webview, not the current URL. )
Share:
2,051
Strange
Author by

Strange

Updated on December 09, 2022

Comments

  • Strange
    Strange over 1 year

    I am using Flutter WebView Plugin to create webview in Flutter app. I have added a reload icon inside the appBar. In order to make the reload icon functional, I want to get the current URL from webview.

    WebView:

    return new MaterialApp(
          theme
            : new ThemeData(
            primaryColor: Color.fromRGBO(58, 66, 86, 1.0), fontFamily: 'Raleway'),
          routes: {
            "/": (_) => new WebviewScaffold(
              url: url,
              appBar: new AppBar(
                title: Text(title),
                actions: <Widget>[
                  IconButton(
                    icon: Icon(Icons.refresh, color: Color.fromRGBO(255, 255, 255, 1.0),),
                    onPressed: () => flutterWebviewPlugin.reloadUrl(url), // this is reloading the url that was provided to webview, not the current URL.
                  )
                ],
              ),
              withJavascript: true,
              withLocalStorage: true,
              appCacheEnabled: true,
              hidden: true,
              initialChild: Container(
                child: const Center(
                  child: CircularProgressIndicator(),
                ),
              ),
            )
          },
        );
    

    Is there any function to get the current URL from webview or any other method? Please help.