freePort method
A port nothing on this machine is listening on — for a server the world hosts.
Implementation
Future<int> freePort() async {
var socket = await ServerSocket.bind(InternetAddress.loopbackIPv4, 0);
var port = socket.port;
await socket.close();
return port;
}