3
0
Fork 0
trifid_mobile/lib/models/IPAndPort.dart

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

30 lines
582 B
Dart
Raw Permalink Normal View History

2021-04-23 21:23:06 +00:00
class IPAndPort {
String? ip;
int? port;
2020-07-27 20:43:58 +00:00
2021-04-23 21:23:06 +00:00
IPAndPort({this.ip, this.port});
2020-07-27 20:43:58 +00:00
@override
String toString() {
if (ip != null && ip!.contains(':')) {
2021-04-23 21:23:06 +00:00
return '[$ip]:$port';
}
2020-07-27 20:43:58 +00:00
return '$ip:$port';
}
String toJson() {
return toString();
}
factory IPAndPort.fromString(String val) {
2021-04-23 21:23:06 +00:00
//TODO: Uri.parse is as close as I could get to parsing both ipv4 and v6 addresses with a port without bringing a whole mess of code into here
final uri = Uri.parse("ugh://$val");
return IPAndPort(
ip: uri.host,
port: uri.port,
);
2020-07-27 20:43:58 +00:00
}
}