pichillilorenzo / flutter_inappwebview

A Flutter plugin that allows you to add an inline webview, to use a headless webview, and to open an in-app browser window.
https://inappwebview.dev
Apache License 2.0
3.31k stars 1.64k forks source link

使用initialData加载html点击按钮切换 htmlContent 字符串内容重新加载,但是webview不更新,为什么? #639

Closed anfenglei9527 closed 1 month ago

anfenglei9527 commented 3 years ago

dart `InAppWebView( // initialUrl: _webUrl, initialData: InAppWebViewInitialData(data: "" + htmlContent + ""), initialOptions: InAppWebViewGroupOptions( crossPlatform: InAppWebViewOptions( javaScriptCanOpenWindowsAutomatically: true, mediaPlaybackRequiresUserGesture: false, debuggingEnabled: true, transparentBackground: true, supportZoom: false, clearCache: true, cacheEnabled: false, useShouldOverrideUrlLoading: true, useOnLoadResource: true, javaScriptEnabled: true, incognito: true, // horizontalScrollBarEnabled: false, userAgent: "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.4) Gecko/20100101 Firefox/4.0", ), android: AndroidInAppWebViewOptions( supportMultipleWindows: true,

                      // useWideViewPort: true,
                      // loadWithOverviewMode: true,
                      // initialScale: 1,
                    ),
                  ),

                  onWebViewCreated: (InAppWebViewController controller) {
                    InAppWebViewController _webViewController = controller;
                    /*        _webViewController.loadData(
                        data: "" + htmlContent + ""); */
                    _webViewController = controller;
                    _webViewController.addJavaScriptHandler(
                        handlerName: 'handlerFooWithArgs',
                        callback: (args) {
                          if (args[0] > 0) {
                            print(args);
                            setState(() {
                              _htmlHeight = args[0].toDouble();
                            });
                          } // it will print: [1, true, [bar, 5], {foo: baz}, {bar: bar_value, baz: baz_value}]
                        });
                  },
                  onLoadStart:
                      (InAppWebViewController controller, String url) {
                    print("##onloadstart: " + url);
                  },
                  onLoadStop: (InAppWebViewController controller,
                      String url) async {
                    print("##onloadstop: $url");
                  },
                  //监听网页加载的进度
                  onProgressChanged:
                      (InAppWebViewController controller, int progress) {
                    print(progress);
                    setState(() {
                      this.progress = progress;
                    });
                  },
                )`

buton ` GestureDetector( onTap: () { if (downdata.length > 0) { setState(() { htmlContent =‘新内容’; }); } }, child: Text("下一条:", style: TextStyle( decoration: TextDecoration.none, color: Color(0xff43F4E0), // fontFamily: '宋体', letterSpacing: 1.0, fontWeight: FontWeight.w100, fontSize: 20.0)),

)`

github-actions[bot] commented 1 month ago

This issue is stale and has been automatically closed because it has been open for more than 365 days with no activity. Please reopen a new issue if you still have it.

github-actions[bot] commented 1 month ago

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug and a minimal reproduction of the issue.