How to get height of the every url of webView flutter

824 views Asked by At

here I get the initial URL height, but when I go to another URL using webviewController.loadUrl() its doesn't change height, how can I found loadUrl height

here the initial URL code:

       SizedBox(
                height: _heights,
                child: WebView(
                  initialUrl: initialUrl,
                  javascriptMode: JavascriptMode.unrestricted,
                  onPageFinished: (some) async {
                    double height = double.parse(await webViewController!
                        .runJavascriptReturningResult(
                            "document.documentElement.scrollHeight;"));
                    setState(() {
                      _heights = height;
                    });
                  },

         
                  onWebViewCreated: (controller) {
                    webViewController = controller;
                  },
                  onProgress: (progress) => setState(
                    () {
                      Progress = progress / 100;
                    },
                  ),
                ),
              ),

and here the load URL code:

       Card(
                child: ListTile(
                  leading: const Icon(Icons.phone),
                  onTap: () {
                    webViewController!.loadUrl(contact);
                    scaffoldKey.currentState?.openEndDrawer();
               
                  },
                  title: Transform.translate(
                    offset: const Offset(-16, 0),
                    child: const Text('Contact Us',
                        style: TextStyle(fontSize: 15.0)),
                  ),
                ),
              ),
       
1

There are 1 answers

3
Akshay Kumar U On

Pass the height as a query parameter in your url. and use that to update the screen height of your Webview.

URL : domain.xyz/?height=100 like this

In flutter widget

Uri url = new Url([url link]);
var height = uri.base.queryParameters['height']