簡體   English   中英

如何為 Flutter WebView 實施拉動刷新

[英]How to implement pull to refresh for Flutter WebView

我在執行 pull 以刷新 flutter 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(),
        ],
      );
    },
  ),
);
}

我曾嘗試在互聯網上搜索,但由於方法不同且令人困惑,因此沒有任何效果。 請幫我。 謝謝

您必須調用 WebviewController 的 reload 方法

創建 Webview Controller

WebViewController _webViewController;

在你的 Webview

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

然后調用_controller.reload(); 在拉。 您可以使用 Pull_to_refresh Package

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM