parseAddress function Null safety

Uri parseAddress(
  1. String address,
  2. int port
)

Parse configured base_url.

This will extract address properties from both 127.0.0.1 or http://127.0.0.1/ and configuration is more permissive.

Implementation

Uri parseAddress(String address, int port) {
  if (_addressPattern.hasMatch(address)) {
    final match = _hostPattern.firstMatch(address);
    final host = address.substring(match!.start, match.end);
    return Uri(scheme: 'http', host: host, port: port);
  } else {
    throw ConfigError('Invalid address format: $address');
  }
}