getContentHeight method
Gets the height of the HTML content.
NOTE for Web: this method will have effect only if the iframe has the same origin.
NOTE for MacOS: it is implemented using JavaScript.
Officially Supported Platforms/Implementations:
- Android native WebView (Official API - WebView.getContentHeight)
- iOS (Official API - UIScrollView.contentSize)
- MacOS
- Web (Official API - Document.documentElement.scrollHeight)
Implementation
@override
Future<int?> getContentHeight() async {
Map<String, dynamic> args = <String, dynamic>{};
var height = await channel?.invokeMethod('getContentHeight', args);
if (height == null || height == 0) {
// try to use javascript
var scrollHeight = await evaluateJavascript(
source: "document.documentElement.scrollHeight;");
if (scrollHeight != null && scrollHeight is num) {
height = scrollHeight.toInt();
}
}
return height;
}