6

I have used inappwebview in our app. I am getting different encodedUrl in shouldOverrideUrlLoading method for iOS and Android. While in iOS it is working fine but for android it is not giving proper url.

encodedURL iOS : %22coordinates%22:%22%7B%5C%22y1%5C%22:193.0,%5C%22x1%5C%22:491.0,%5C%22y2%5C%22:162.0,%5C%22x2%5C%22:522.0%7D%22
android : %22coordinates%22:%22%7B/%22y1/%22:521.0,/%22x1/%22:753.0,/%22y2/%22:490.0,/%22x2/%22:784.0%7D%22

DecoddedURL iOS : "coordinates":"{"y1":521.0,"x1":753.0,"y2":490.0,"x2":784.0}" android : "coordinates":"{/"y1/":521.0,/"x1/":753.0,/"y2/":490.0,/"x2/":784.0}"

we are getting different different encoded string for iOS and Android. You can see “coordinates” value for iOS it is coming '%5C' and for android it is '/'.

InAppWebView(
          key: webViewKey,
          initialUrlRequest: URLRequest(url: Uri.parse(widget.url)),
          initialOptions: inAppWebViewGroupOptions(),
          onWebViewCreated: (InAppWebViewController webViewController) async {
            _appWebViewController = webViewController;
            if (widget.onWebViewCreated != null) {
              widget.onWebViewCreated!(_appWebViewController!);
            }
          },
          onLoadStart: (InAppWebViewController controller, Uri? url) async {
            if (widget.onProgressChanged != null) {
              widget.onPageStarted!(url.toString());
            }
          },
          onLoadStop: (InAppWebViewController controller, Uri? url) async {
            if (widget.onPageFinished != null) {
              widget.onPageFinished!(url.toString());
            }
          },
          onProgressChanged: (InAppWebViewController controller, int progress) {
            if (widget.onProgressChanged != null) {
              widget.onProgressChanged!(progress);
            }
          },
          shouldOverrideUrlLoading: (controller, navigationAction) async {
            var request = navigationAction.request;
            var url = request.url;
            bool absolute = url!.hasAbsolutePath;

            if (absolute) {
              setCookies(url.toString());
            }

            if (widget.shouldOverrideUrlLoading != null) {
              widget.shouldOverrideUrlLoading!(controller, navigationAction);
            }
            // always allow all the other requests
            return NavigationActionPolicy.ALLOW;
          },
          androidOnPermissionRequest: (controller, origin, resources) async {
            return PermissionRequestResponse(
                resources: resources,
                action: PermissionRequestResponseAction.GRANT);
          },
          onLoadError: (_, __, int code, String message) {
            if (widget.onPageError != null) {
              widget.onPageError!(code, message);
            }
            _webViewCubit?.showLinearProgressIndicator(false, 1);
          },
        );

Please find below code for getting decodedURL:

String jsonString = Uri.decodeFull(data[1]);

So is there any way to get values same in android like iOS?

AsiteUser
  • 217
  • 1
  • 4

0 Answers0