Flutter InAppWebView evaluateJavascript is not working correclty

53 views Asked by At

I am using the InAppWebView and need to call evaluateJavascript. The documentation says the following:

...Instead, you should call this method, for example, inside the [PlatformWebViewCreationParams.onLoadStop] event or in any other events where you know the page is ready "enough".

So I am calling it like this:

  onLoadStop: (InAppWebViewController controller, Uri? url) async {
    await _webViewController?.evaluateJavascript(
      source: _javascriptString!,
    );
  },

However my javascript is not correctly evaulated. Some data is not being send.

The only fix I found is to wait:

  onLoadStop: (InAppWebViewController controller, Uri? url) async {
    // // ABSOLUTELY NO IDEA WHY, but this fixes the issue.
    await Future.delayed(
      Duration(milliseconds: 1000),
    );

    await _webViewController?.evaluateJavascript(
      source: _javascriptString!,
    );
  },

For me that means that the page is not completely loaded when evaluateJavascript is called.

Any idea what this issue can be? Let me know if you need more information.

0

There are 0 answers