3

I'm using url_launcher (6.1.5) and I want open the urls in default browser instead of in-app webView.

It seems that the latest version does not support it, since launch function is deprecated, and launchUrl does not support the forceWebView=false flag.

How do I run my url on default browser using url_launcher?

1 Answer 1

31

TL;DR

You can use the LaunchMode.externalApplication parameter.

await launchUrl(_url, mode: LaunchMode.externalApplication);

More info

By default the mode value is set to LaunchMode.platformDefault, which in most cases is an inAppWebView.

Changing the mode solved this issue:

Future<void> openUrl(String url) async {
  final _url = Uri.parse(url);
  if (!await launchUrl(_url, mode: LaunchMode.externalApplication)) { // <--
    throw Exception('Could not launch $_url');
  }
}

LaunchMode support several arguments:

enum LaunchMode {
  /// Leaves the decision of how to launch the URL to the platform
  /// implementation.
  platformDefault,

  /// Loads the URL in an in-app web view (e.g., Safari View Controller).
  inAppWebView,

  /// Passes the URL to the OS to be handled by another application.
  externalApplication,

  /// Passes the URL to the OS to be handled by another non-browser application.
  externalNonBrowserApplication,
}
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.