launchURL static method

void launchURL(
  1. String url
)

Launches a URL in an external application/browser.

Attempts to open the provided URL in an external application using the system's default handler (e.g., web browser for HTTP URLs, phone app for tel: URLs).

Parameters:

  • url: The URL string to launch (e.g., "https://example.com", "tel:+1234567890")

Throws an exception with message 'Could not launch $url' if the URL cannot be opened. This can happen if:

  • The URL format is invalid
  • No application can handle the URL scheme
  • User permissions are insufficient

Example:

// Launch website
RtCommonFunction.launchURL('https://flutter.dev');

// Make phone call
RtCommonFunction.launchURL('tel:+1234567890');

// Send email
RtCommonFunction.launchURL('mailto:support@example.com');

The URL is launched in external mode (LaunchMode.externalApplication), opening the URL outside your app in the appropriate system application.

Implementation

static void launchURL(String url) async {
  if (await canLaunchUrl(Uri.parse(url))) {
    await launchUrl(
      Uri.parse(url),
      mode: LaunchMode.externalApplication,
    );
  } else {
    throw 'Could not launch $url';
  }
}