【问题标题】:How to implement pull to refresh for Flutter WebViewFlutter WebView如何实现pull to refresh
【发布时间】:2021-12-07 05:02:06
【问题描述】:

我在实现拉动以刷新颤动的 WebView 时遇到问题。我的应用程序由单屏和当前网页组成。当我尝试使用 RefreshIndicator 时,我很困惑如何实现,但它没有用。 这是我的代码

@override
Widget build(BuildContext context) {
return Scaffold(
  appBar: PreferredSize(
    preferredSize: MediaQuery.of(context).size * 0.05,
    child: AppBar(
      //leading: Image.asset(gnTabIcon),
      elevation: 3.5,
      shadowColor: AppColors.navyBlue,
      backgroundColor: AppColors.orange,
      title: const Text(title),
      actions: <Widget>[
        NavigationControls(_controller.future), // control navigation
      ],
    ),
  ),


  // build scaffold for main app
  body: Builder(
    builder: (BuildContext context) {
      return Stack(
        children: [
          Padding(
            padding: const EdgeInsets.fromLTRB(0, 0, 0, 15.0),
            child: WebView(
              gestureNavigationEnabled: false,
              initialUrl: url,
              javascriptMode: JavascriptMode.unrestricted,
              zoomEnabled: false, // disable pinch to zoom

              onWebViewCreated: (webViewController) {
                print('WebView is created');
                _controller.complete(webViewController);
              },
              onProgress: (int progress) {
                print("WebView is loading (progress : $progress%)");
                splashScreenDelay(progress);
              },
              javascriptChannels: <JavascriptChannel>{
                _toasterJavascriptChannel(context),
              },

              onPageStarted: (String url) {
                print('Page started loading: $url');
                _loadingStateTrue();
              },
              onPageFinished: (String url) {
                print('Page finished loading: $url');
                _loadingStateFalse();
              },
            ),
          ),
          isLoading
              ? Center(
                  child: GnLoader(),
                )
              : Stack(),
        ],
      );
    },
  ),
);
}

我曾尝试在互联网上进行搜索,但由于方法不同且令人困惑,因此没有任何效果。请帮我。谢谢

【问题讨论】:

    标签: flutter dart webview


    【解决方案1】:

    你必须调用你的 WebviewController 的 reload 方法

    创建 Webview 控制器

    WebViewController _webViewController;
    

    在您的网络视图中

    onWebViewCreated: (WebViewController webViewController) {
                    _controller = webViewController;
    },
    

    然后在 Pull 中调用 _controller.reload();。 您可以使用 Pull_to_refresh 包

    【讨论】:

    • 我尝试这样做,但收到此错误“未处理的异常:空值检查运算符用于空值 #0 _GimmeNowWebState._onRefresh (package:gn_mobile_flutter_customer_mobile_web/views/gn_webview.dart:134:23) "
    猜你喜欢
    • 2011-06-02
    • 2021-03-17
    • 1970-01-01
    • 2014-05-11
    • 2015-04-11
    • 1970-01-01
    • 1970-01-01
    • 2016-10-13
    • 2013-01-14
    相关资源
    最近更新 更多