domainToUnicode function

String domainToUnicode(
  1. String domain
)

Converts a domain name from Punycode-encoded ASCII to Unicode.

Implementation

String domainToUnicode(String domain) {
  final labels = domain.split('.');
  final decodedLabels = labels.map((label) {
    if (label.toLowerCase().startsWith('xn--')) {
      return punycode.decode(label.substring(4));
    }
    return label;
  });

  return decodedLabels.join('.');
}