resolveUri function
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 usebaseUri
parameter or getUriBase result.baseUri
Base URI to use. If is null will use getUriBase result.- If both
baseUri
andbaseURL
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);
}