【发布时间】:2023-02-16 18:28:21
【问题描述】:
我使用 InAppWebView 在我们的应用程序中显示网页内容。
为了确保它只占用必要的空间,我听了 onLoadStop 回调,然后设置了 SizedBoxs 高度。
在那里我尝试获取内容高度:
final height = await controller.getContentHeight();
但它总是返回 0。
在 iOS 上,我总能得到正确的高度。
【问题讨论】:
我使用 InAppWebView 在我们的应用程序中显示网页内容。
为了确保它只占用必要的空间,我听了 onLoadStop 回调,然后设置了 SizedBoxs 高度。
在那里我尝试获取内容高度:
final height = await controller.getContentHeight();
但它总是返回 0。
在 iOS 上,我总能得到正确的高度。
【问题讨论】:
问题是 Android 过早地调用了 Android Webview 的onPageFinished 回调。
添加
if (Platform.isAndroid) {
await Future.delayed(
const Duration(milliseconds: 1000),
);
}
解决问题并
final height = await controller.getContentHeight();
返回正确的高度。
【讨论】: