open method

Future<Window?> open({
  1. required CSchemeType scheme,
  2. bool popupWindow = false,
  3. CMailToParams? mailtoParams,
  4. String? url,
  5. String target = "_blank",
  6. double? width,
  7. double? height,
})

Loads a specified resource into a new or existing browsing context (that is, a tab, a window, or an iframe) under a specified name. These are based on the different CSchemeType supported protocol items.

See https://developer.mozilla.org/en-US/docs/Web/API/Window/open

Implementation

Future<web.Window?> open({
  required CSchemeType scheme,
  bool popupWindow = false,
  CMailToParams? mailtoParams,
  String? url,
  String target = "_blank",
  double? width,
  double? height,
}) async {
  try {
    var urlToLaunch = "";
    if (scheme == CSchemeType.file ||
        scheme == CSchemeType.http ||
        scheme == CSchemeType.https ||
        scheme == CSchemeType.sms ||
        scheme == CSchemeType.tel) {
      urlToLaunch = scheme.getUrl(url!);
    } else {
      urlToLaunch = mailtoParams != null
          ? scheme.getUrl(mailtoParams.toString())
          : scheme.getUrl(url!);
    }

    if (popupWindow) {
      var w = width ?? 900.0;
      var h = height ?? 600.0;
      var top = (web.window.screen.height - h) / 2;
      var left = (web.window.screen.width - w) / 2;
      var settings = "toolbar=no, location=no, "
          "directories=no, status=no, menubar=no, "
          "scrollbars=no, resizable=yes, copyhistory=no, "
          "width=$w, height=$h, top=$top, left=$left";
      return web.window.open(
        urlToLaunch,
        "_blank",
        settings,
      );
    }

    return web.window.open(urlToLaunch, target);
  } catch (ex, st) {
    codemelted_logger.error(data: ex, stackTrace: st);
    return null;
  }
}