isValid static method
- String value
Returns true if value is a syntactically valid IPv6 address string.
Implementation
static bool isValid(String value) {
if (value.isEmpty) return false;
// At most one '::' is allowed in any IPv6 address.
final dcCount = '::'.allMatches(value).length;
if (dcCount > 1) return false;
final hasDoubleColon = dcCount == 1;
// Detect an IPv4-mapped tail (e.g. ::ffff:1.2.3.4).
// The IPv4 portion appears after the last ':' when the string contains a
// dotted-quad pattern.
final lastColon = value.lastIndexOf(':');
if (lastColon >= 0) {
final tail = value.substring(lastColon + 1);
if (tail.contains('.')) {
// The tail looks like an IPv4 address — validate as IPv4-mapped.
return _validateIpv4Mapped(value, tail, hasDoubleColon);
}
}
// Pure hex form (no IPv4 tail).
if (hasDoubleColon) {
return _validateCompressed(value);
} else {
return _validateFull(value);
}
}