IPAddress constructor
IPAddress(
- String? str
Returns a valid IPAddress object.
Throws ValueException:
- RequiredValueException if
str
is null or empty. - InvalidValueException if
str
is not a valid IPv4 or IPv6 address.
Implementation
factory IPAddress(String? str) {
if (str == null || str.isEmpty) {
throw const RequiredValueException();
}
if (isIP(str, '4')) {
return IPAddress._(str, IPVersion.v4);
} else if (isIP(str, '6')) {
return IPAddress._(str, IPVersion.v6);
}
throw InvalidValueException(
str,
message: '$str is not a valid IP address',
);
}