在 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 "),
],
)
最佳答案
如果你想将你的可滚动 WebView 放在其他小部件之间,并且 WebView 将是可滚动的,而其他小部件不是,那么只需将你的 ListView 更改为 Column 这样:
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 "),
)
但是如果你想在 WebView 之上有一些可滚动的小部件,那么试试 CustomScrollView或 SliverList .
你能说出你试图制定的确切逻辑是什么吗?
补充:
如果你想有可滚动区域和一些内部的 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 "),
],
);
可以动态获取的WebView的高度,灵感在这里: https://gist.github.com/PonnamKarthik/877a90917a576ecff613d5169680d02c
关于flutter - 内部没有高度的 WebView 滚动不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58694353/