launchURL static method

void launchURL(
  1. String url, {
  2. bool openInApp = true,
  3. bool clearCache = false,
  4. bool clearCookies = false,
  5. bool sameTab = false,
})

Implementation

static void launchURL(String url, {bool openInApp = true, bool clearCache = false, bool clearCookies = false, bool sameTab = false}) async {
  AppConfig.logger.d('Launching: $url - openInApp: $openInApp');

  try {
    if (await canLaunchUrl(Uri.parse(url))) {

      if(openInApp && UrlUtilities.isExternalDomain(url)) {
        openInApp = false;
      }

      if (kIsWeb && sameTab) {
        // Si estás en la web, abre en la misma pestaña o en una nueva
        // html.window.location.href = url; // Esto abrirá en la misma pestaña
      } else {
        if(clearCache) await clearWebViewCache();
        if(clearCookies) await clearWebViewCookies();

        await launchUrl(Uri.parse(url),
          mode: openInApp ? LaunchMode.inAppWebView : LaunchMode.externalApplication,
        );
      }

    } else {
      AppConfig.logger.i('Could not launch $url');
    }
  } catch(e) {
    AppConfig.logger.e(e.toString());
  }
}