I am sorry it's late but now it's working properly.
I wrapped WebView into a SizedBox and assigned it's height like this:
_webViewController
.evaluateJavascript("document.body.clientHeight")
.then((height) {
print("Height of Page is: $height}");
setState(() {
sizedBoxHeight = double.parse(height);
});
});
For a more advanced solution we can use JavascriptChannels like this:
javascriptChannels: Set.from([
JavascriptChannel(
name: 'RenderedWebViewHeight',
onMessageReceived: (JavascriptMessage message) {
setState(() {
sizedBoxHeight = double.parse(message.message);
});
]),
In JavaScript, we can do something like this.
onload="RenderedWebViewHeight.postMessage(document.body.clientHeight);"
Now we can see it's dynamically calculating the height of WebView which is wrapped in a SizedBox with the height WebView so we can put it into a ListView.
For a more detailed solution, you can look at webview_flutter_plus.
Edit:
document.documentElement.scrollHeight
is the most accurate way of doing things. This works with both body margins and margins of stuff inside the body pushing it downwards.
More info in How to get height of entire document with JavaScript