我构建了一个 WebView 应用程序,我想下拉屏幕以刷新网页。我将flutter_inappwebview用于webview。我尝试将 WebView 包装在 SingleChildScrollView 或 ListView 中,但它们都不起作用。在下面的代码中,当滑动功能起作用时,WebView 不可滚动。
我一直在寻找解决方案一段时间,但我找不到它。任何帮助将不胜感激!
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () => _onBackPressed(),
child: Scaffold(
body: SafeArea(
child: RefreshIndicator(
onRefresh: () async {
print("##Refresh");
webview.reload();
},
child: SingleChildScrollView(
physics: AlwaysScrollableScrollPhysics(),
child: Container(
height: MediaQuery.of(context).size.height,
child: Center(
child: Stack(
children: <Widget>[
InAppWebView(
gestureRecognizers: Set()
..add(
Factory<VerticalDragGestureRecognizer>(
() => VerticalDragGestureRecognizer(),
),
),
initialOptions: InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(
debuggingEnabled: true,
userAgent: 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Mobile Safari/537.36',
),
),
onWebViewCreated: (InAppWebViewController controller) {
webview = controller;
controller.loadUrl(url: startURL);
},
onLoadStart: (InAppWebViewController controller, String url) async {
print("##onloadstart: " + url);
},
onLoadStop: (InAppWebViewController controller, String url) async {
print("##onloadstop: $url");
},
onProgressChanged: (InAppWebViewController controller, int progress) {
setState(() {
this.progress = progress / 100;
});
}
),
Align(
alignment: Alignment.center,
child: buildProgressBar(progress),
),
],
),
),
),
),
),
),
),
);
}