flutterwebviewflutter-inappwebview

InAppWebView getContentHeight always returns 0 on Android


I use InAppWebView to display a web content in our app. To ensure that it only takes the necessary space I listen to the onLoadStop callback to then set a SizedBoxs height.

There I try to get the content height:

final height = await controller.getContentHeight();

But it always returns 0.

On iOS I always get the right height.


Solution

  • The problem is that Android calls the onPageFinished callback for the Android Webview too early. Answer found here.

    Adding

    if (Platform.isAndroid) {
       await Future.delayed(
          const Duration(milliseconds: 1000),
       );
    }
    

    solves the problem and

    final height = await controller.getContentHeight();
    

    returns the correct height.