encodeComponent static method

String encodeComponent(
  1. String component
)

Encode the string component using percent-encoding to make it safe for literal use as a URI component.

All characters except uppercase and lowercase letters, digits and the characters -_.!~*'() are percent-encoded. This is the set of characters specified in RFC 2396 and which is specified for the encodeUriComponent in ECMA-262 version 5.1.

When manually encoding path segments or query components, remember to encode each part separately before building the path or query string.

For encoding the query part consider using encodeQueryComponent.

To avoid the need for explicitly encoding, use the pathSegments and queryParameters optional named arguments when constructing a Uri.

Example:

const request = 'http://example.com/search=Dart';
final encoded = Uri.encodeComponent(request);
print(encoded); // http%3A%2F%2Fexample.com%2Fsearch%3DDart

Implementation

static String encodeComponent(String component) {
  return _Uri._uriEncode(_unreserved2396Mask, component, utf8, false);
}