美文网首页
flutter_inappwebview 计算WebView高度

flutter_inappwebview 计算WebView高度

作者: Buddha_like | 来源:发表于2021-07-08 18:14 被阅读0次
tt.jpeg

如果下面的代码帮助到了你,记得点赞!

double height = 1;
///some widgets
Container(
  height: height,
  child: InAppWebView(
    initialOptions: InAppWebViewGroupOptions(
      crossPlatform: InAppWebViewOptions(
        supportZoom: false,
        javaScriptEnabled: true,
        disableHorizontalScroll: true,
        disableVerticalScroll: true,
      ),
    ),
    onWebViewCreated: (InAppWebViewController controller) {
      controller.addJavaScriptHandler(
        handlerName: "newHeight",
        callback: (List<dynamic> arguments) async {
          int? height = arguments.isNotEmpty ? arguments[0] : await controller.getContentHeight();
          if (mounted) setState(() => this.height = height!.toDouble());
        });
    },
    initialUrl: html,
  ),
),

原链接:https://stackoverflow.com/questions/66477207/flutter-and-inappwebview-how-to-get-height

相关文章

网友评论

      本文标题:flutter_inappwebview 计算WebView高度

      本文链接:https://www.haomeiwen.com/subject/xlmtpltx.html