resolveUri function

Uri resolveUri(
  1. String url, {
  2. String? baseURL,
  3. Uri? baseUri,
})

Resolves url and returns an Uri.

If url starts without a scheme, it will use base Uri (from getUriBase) as base.

  • baseURL Base URL to use. If is null will use baseUri parameter or getUriBase result.
  • baseUri Base URI to use. If is null will use getUriBase result.
  • If both baseUri and baseURL are null, if needed, getUriBase will be used.

Implementation

Uri resolveUri(String url, {String? baseURL, Uri? baseUri}) {
  url = url.trim();

  var base =
      baseUri ?? (isNotEmptyString(baseURL) ? Uri.parse(baseURL!) : null);

  if (url.isEmpty) return base ?? getUriBase();

  if (url == '/') return base ?? getUriRoot();

  if (url == './') return base ?? getUriBase();

  if (url.startsWith(RegExp(r'\w+://'))) return Uri.parse(url);

  base ??= getUriBase();

  return buildUri(base.scheme, base.host, base.port,
      path: base.path, path2: url);
}