percentEncodedString property

String get percentEncodedString

Returns the normalized string representation for this HREF, encoded for URL uses.

Taken from https://stackoverflow.com/a/49796882/1474476

Implementation

String get percentEncodedString {
  String string = this.string;
  if (string.startsWith("/")) {
    string = string.addPrefix("file://");
  }

  try {
    Uri url = Uri.parse(string);
    Uri uri = url.replace(host: AsciiCodec().decode(url.host.toUtf8()));
    return String.fromCharCodes(AsciiCodec().encode(uri.toString()))
        .removePrefix("file://");
  } on Exception catch (e) {
    Fimber.e("ERROR in percentEncodedString", ex: e);
    return this.string;
  }
}