Search code examples
flutterurl-launcher

launch method in Flutter url_launcher dart package is deprecated, but launchURL does not have forceSafariVC parameter


"launch" method in Flutter url_launcher dart package is deprecated, and it needs to be replaced to launchURL. But launchURL method does not have forceSafariVC parameter.

How would the migration to this new method look like considering the forceSafariVC parameter?


Solution

  • You need to use LaunchMode. In general (but not in all cases):

    • forceSafariVC: false translates to mode: LaunchMode.externalApplication.

    • forceSafariVC: true translates to mode: LaunchMode.inAppWebView.

    If your app has also non-mobile targets (macOS, Windows, Linux, Web), then you might want to use different modes.

    If you need to handle universal links, then you might want to use

        final nativeAppLaunchSucceeded = await launchUrl(
          url,
          mode: LaunchMode.externalNonBrowserApplication,
        );
        if (!nativeAppLaunchSucceeded) {
          await launchUrl(
            url,
            mode: LaunchMode.inAppWebView,
          );
        }
    

    See the official example.