内部没有高度的WebView Scroll不起作用

Bes*_*del 2 webview flutter

在 Flutter 上……我尝试在所有支持滚动的可用容器中添加 Webview,但它在 Android 上不起作用。

ListView(
          shrinkWrap: true,
          children: <Widget>[
            Text("hiiiiiiiiiiiii "),
            Text("hiiiiiiiiiiiii "),
            Text("hiiiiiiiiiiiii "),
           Expanded(
                child: WebView(
                    key: Key("webview1"),
                    debuggingEnabled:  true,
                    javascriptMode: JavascriptMode.unrestricted,
                    initialUrl: "https://flutter.dev/")),
            Text("hiiiiiiiiiiiii "),
            Text("hiiiiiiiiiiiii "),
            Text("hiiiiiiiiiiiii "),
          ],
)
Run Code Online (Sandbox Code Playgroud)

dub*_*ace 10

如果您想将您的可滚动 WebView 放在其他小部件之间,并且 WebView 将是可滚动的,而其他小部件则不是,那么只需像这样更改 Column 的 ListView:

Column(
  children: <Widget>[
    Text("hiiiiiiiiiiiii "),
    Text("hiiiiiiiiiiiii "),
    Container(
      height: 300,
      child: WebView(
          key: Key("webview1"),
          debuggingEnabled: true,
          javascriptMode: JavascriptMode.unrestricted,
          initialUrl: "https://flutter.dev/")
    ),
    Text("hiiiiiiiiiiiii "),
    Text("hiiiiiiiiiiiii "),
)
Run Code Online (Sandbox Code Playgroud)

但是如果你想在 WebView 之上有一些可滚动的小部件,那么试试 CustomScrollViewSliverList

你能说出你想要制作的确切逻辑吗?

补充:

如果你想在里面有可滚动区域和一些 WebView,你必须知道 WebView 的高度:

ListView(
  physics: ClampingScrollPhysics(),
  children: <Widget>[
    Text("hiiiiiiiiiiiii "),
    Text("hiiiiiiiiiiiii "),
    ConstrainedBox(
      constraints: BoxConstraints(maxHeight: 10000),
        child: WebView(
          gestureRecognizers: Set()
            ..add(
              Factory<VerticalDragGestureRecognizer>(
                  () => VerticalDragGestureRecognizer(),
              ), // or null
            ),
            key: Key("webview1"),
            debuggingEnabled: true,
            javascriptMode: JavascriptMode.unrestricted,
            initialUrl: "https://flutter.dev/")),
    Text("hiiiiiiiiiiiii "),
    Text("hiiiiiiiiiiiii "),
  ],
);
Run Code Online (Sandbox Code Playgroud)

您可以动态获取的 WebView 高度,灵感在这里:https : //gist.github.com/PonnamKarthik/877a90917a576ecff613d5169680d02c