【问题标题】:InAppWebView getContentHeight always returns 0 on AndroidInAppWebView getContentHeight 在 Android 上总是返回 0
【发布时间】:2023-02-16 18:28:21
【问题描述】:

我使用 InAppWebView 在我们的应用程序中显示网页内容。 为了确保它只占用必要的空间,我听了 onLoadStop 回调,然后设置了 SizedBoxs 高度。

在那里我尝试获取内容高度:

final height = await controller.getContentHeight();

但它总是返回 0。

在 iOS 上,我总能得到正确的高度。

【问题讨论】:

    标签: flutter webview


    【解决方案1】:

    问题是 Android 过早地调用了 Android Webview 的onPageFinished 回调。

    添加

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

    解决问题并

    final height = await controller.getContentHeight();
    

    返回正确的高度。

    【讨论】:

      猜你喜欢
      • 2014-05-30
      • 1970-01-01
      • 2011-06-16
      • 2011-09-29
      • 2015-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-14
      相关资源
      最近更新 更多