Uri({String scheme: "", String userInfo: "", String host, int port, String path, Iterable<String> pathSegments, String query, Map<String, dynamic> queryParameters, String fragment})

Creates a new URI from its components.

Each component is set through a named argument. Any number of components can be provided. The path and query components can be set using either of two different named arguments.

The scheme component is set through scheme. The scheme is normalized to all lowercase letters. If the scheme is omitted or empty, the URI will not have a scheme part.

The user info part of the authority component is set through userInfo. It defaults to the empty string, which will be omitted from the string representation of the URI.

The host part of the authority component is set through host. The host can either be a hostname, an IPv4 address or an IPv6 address, contained in '' and ''. If the host contains a ':' character, the '' and '' are added if not already provided. The host is normalized to all lowercase letters.

The port part of the authority component is set through port. If port is omitted or null, it implies the default port for the URI's scheme, and is equivalent to passing that port explicitly. The recognized schemes, and their default ports, are "http" (80) and "https" (443). All other schemes are considered as having zero as the default port.

If any of userInfo, host or port are provided, the URI has an autority according to hasAuthority.

The path component is set through either path or pathSegments. When path is used, it should be a valid URI path, but invalid characters, except the general delimiters ':/@?#', will be escaped if necessary. When pathSegments is used, each of the provided segments is first percent-encoded and then joined using the forward slash separator.

The percent-encoding of the path segments encodes all characters except for the unreserved characters and the following list of characters: !$&'()*+,;=:@. If the other components necessitate an absolute path, a leading slash / is prepended if not already there.

The query component is set through either query or queryParameters. When query is used, the provided string should be a valid URI query, but invalid characters, other than general delimiters, will be escaped if necessary. When queryParameters is used the query is built from the provided map. Each key and value in the map is percent-encoded and joined using equal and ampersand characters. A value in the map must be either a string, or an Iterable of strings, where the latter corresponds to multiple values for the same key.

The percent-encoding of the keys and values encodes all characters except for the unreserved characters, and replaces spaces with +. If query is the empty string, it is equivalent to omitting it. To have an actual empty query part, use an empty map for queryParameters.

If both query and queryParameters are omitted or null, the URI has no query part.

The fragment component is set through fragment. It should be a valid URI fragment, but invalid characters other than general delimiters, are escaped if necessary. If fragment is omitted or null, the URI has no fragment part.

Source

factory Uri({String scheme : "",
             String userInfo : "",
             String host,
             int port,
             String path,
             Iterable<String> pathSegments,
             String query,
             Map<String, dynamic/*String|Iterable<String>*/> queryParameters,
             String fragment}) {
  scheme = _makeScheme(scheme, 0, _stringOrNullLength(scheme));
  userInfo = _makeUserInfo(userInfo, 0, _stringOrNullLength(userInfo));
  host = _makeHost(host, 0, _stringOrNullLength(host), false);
  // Special case this constructor for backwards compatibility.
  if (query == "") query = null;
  query = _makeQuery(query, 0, _stringOrNullLength(query), queryParameters);
  fragment = _makeFragment(fragment, 0, _stringOrNullLength(fragment));
  port = _makePort(port, scheme);
  bool isFile = (scheme == "file");
  if (host == null &&
      (userInfo.isNotEmpty || port != null || isFile)) {
    host = "";
  }
  bool hasAuthority = (host != null);
  path = _makePath(path, 0, _stringOrNullLength(path), pathSegments,
                   scheme, hasAuthority);
  if (scheme.isEmpty && host == null && !path.startsWith('/')) {
    path = _normalizeRelativePath(path);
  } else {
    path = _removeDotSegments(path);
  }
  return new Uri._internal(scheme, userInfo, host, port,
                           path, query, fragment);
}