launchUrl function

Future<bool> launchUrl(
  1. Uri url, {
  2. LaunchMode mode = LaunchMode.platformDefault,
  3. WebViewConfiguration webViewConfiguration = const WebViewConfiguration(),
  4. String? webOnlyWindowName,
  5. String? webOnlyOptions,
})

Passes url to the underlying platform for handling.

mode support varies significantly by platform:

For web, webOnlyWindowName specifies a target for the launch. This supports the standard special link target names. For example:

  • "_blank" opens the new URL in a new tab.
  • "_self" opens the new URL in the current tab. Default behaviour when unset is to open the url in a new tab.

Returns true if the URL was launched successful, otherwise either returns false or throws a PlatformException depending on the failure.

Implementation

Future<bool> launchUrl(
  Uri url, {
  LaunchMode mode = LaunchMode.platformDefault,
  WebViewConfiguration webViewConfiguration = const WebViewConfiguration(),
  String? webOnlyWindowName,
  String? webOnlyOptions,
}) async {
  if (mode == LaunchMode.inAppWebView &&
      !(url.scheme == 'https' || url.scheme == 'http')) {
    throw ArgumentError.value(url, 'url',
        'To use an in-app web view, you must provide an http(s) URL.');
  }
  return UrlLauncherPlatform.instance.launchUrl(
    url.toString(),
    LaunchOptions(
      mode: convertLaunchMode(mode),
      webViewConfiguration: convertConfiguration(webViewConfiguration),
      webOnlyWindowName: webOnlyWindowName,
      webOnlyOptions: webOnlyOptions,
    ),
  );
}