isPort function
Returns true if input is an integer port in the range 0–65535.
Implementation
bool isPort(Object? input) {
num? port;
if (input is String) {
port = num.tryParse(input);
} else if (input is num) {
port = input;
}
if (port != null && port.toInt() != port) {
return false;
}
return port != null && 0 <= port && port <= 65535;
}