Wednesday, December 7, 2022
HomeiOS Developmentandroid - Flutter inappwebview shouldoverride url loading not working

android – Flutter inappwebview shouldoverride url loading not working


In my app, i’m utilizing flutter inappwebview to load url, however i discovered that mailto:,tel:,sms: url cannot be loaded within the browser, i did my analysis and used the useShouldOverrideUrlLoading property in webview , but it surely don’t appear to work.

initialOptions: InAppWebViewGroupOptions(
                      crossPlatform: InAppWebViewOptions(
                        useShouldOverrideUrlLoading: true,
                      ),
                      android: AndroidInAppWebViewOptions(
                        forceDark:
                            Theme.of(context).brightness == Brightness.darkish
                                ? AndroidForceDark.FORCE_DARK_ON
                                : AndroidForceDark.FORCE_DARK_OFF,
                        useHybridComposition: widget.useHybridComposition,
                      ),
                    ),
                    shouldOverrideUrlLoading:
                        (InAppWebViewController controller,
                            NavigationAction shouldOverrideUrl) async {
                      print('that is an intercept');
                      Uri url = shouldOverrideUrl.request.url;
                      String motion = url.scheme;
                      Record<String> customActions = [
                        "http",
                        "https",
                        "file",
                        "chrome",
                        "data",
                        "javascript",
                        "about"
                      ];
                      if (!customActions.comprises(motion)) {
                        if (await canLaunch(url.toString())) {
                          await launch(url.toString());
                        }
                        return NavigationActionPolicy.CANCEL;
                      }
                      return NavigationActionPolicy.ALLOW;
                    },

the model of flutter_inappwebview

flutter_inappwebview: ^5.4.3+7

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments