flutter webview 允许下拉刷新的方法

更新时间:2023-05-25 21:55
在webview外包裹下拉刷新等组件后,webview插件不能渲染整个页面.使用下面的方法可以解决
使手势识别器刷新,只需在您的 Webview 小部件中添加以下代码‎

 

WebView(
              key: UniqueKey(),
              initialUrl: 'https://...',
              javascriptMode: JavascriptMode.unrestricted,
              onWebViewCreated: (WebViewController webViewController) {
                _controller = webViewController;
              },
              onPageFinished: (String str) {
                myModel.stopLoading();
              },
              onPageStarted: (String str) {
                myModel.startLoading();
              },
              gestureRecognizers: Set()
                ..add(Factory<VerticalDragGestureRecognizer>(
                    () => VerticalDragGestureRecognizer()
                      ..onDown = (DragDownDetails dragDownDetails) {
                        _controller.getScrollY().then((value) {
                          if (value == 0 &&
                              dragDownDetails.globalPosition.direction < 1) {
                            _controller.reload();
                          }
                        });
                      })),
            ),