0

I am opening a website using the Flutter InAppWebView.

           child: InAppWebView(
                  initialUrlRequest: URLRequest(
                    url: Uri.parse("https://mywebsite.com"),
                  ),
                  androidOnGeolocationPermissionsShowPrompt:
                      (InAppWebViewController controller, String origin) async {
                    return GeolocationPermissionShowPromptResponse(
                        origin: origin,
                        allow: true,
                        retain: true
                    );
                  },
                  initialOptions: options,
                  onWebViewCreated: (InAppWebViewController controller) {
                    _webViewController = controller;
                  },
                  androidOnPermissionRequest: (InAppWebViewController controller, String origin, List<String> resources) async {
                    return PermissionRequestResponse(resources: resources, action: PermissionRequestResponseAction.GRANT);
                  }
              ),

This website calls a URL:https://www.google.com/maps/search/?api=1&query=$latitude,$longitude' on button click.

This doesn't open the Application and rather continues in the InAppWebView. How do I resolve this?

2
  • Have you figured it out? I am facing the same issue Commented Jul 6, 2022 at 18:59
  • Sadly no @ApurvaAgrawal, I had to do some workaround tweak to the UI. Commented Jul 11, 2022 at 7:51

1 Answer 1

0

I know how you can handle this one.

you need to parse the URL and launch an app where possible. This is easy enough if you've done the basic setup so;

import 'package:url_launcher/url_launcher.dart';

This is required to launch the maps app where applicable. The standard sample is;

shouldOverrideUrlLoading:
    (controller, navigationAction) async {
    var uri = navigationAction.request.url!;

    if (![
        "http",
        "https",
        "file",
        "chrome",
        "data",
        "javascript",
        "about"
    ].contains(uri.scheme)) {
         if (await canLaunchUrl(uri)) {
             // Launch the App
             await launchUrl(
                 uri,
             );
             // and cancel the request
             return NavigationActionPolicy.CANCEL;
         }
    }
    return NavigationActionPolicy.ALLOW;
},

we want to look at the url and launch where a map is required. So to that end I've added this before the final return.

    if(uri.toString().contains("maps.google")){
        if (await canLaunchUrl(uri)) {
             // Launch the App - should be maps if installed
             await launchUrl(
                 uri,
             );
             // and cancel the request
             return NavigationActionPolicy.CANCEL;
         }
    }

Hope this helps anyone stuck.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.