fromString static method
Creates a CustomProxy instance from a string representation.
The proxy string should be in the format "ipAddress:port".
For example: "192.168.1.1:8080"
Returns null if:
- The proxy string is empty
- The port number cannot be parsed to an integer
Throws an AssertionError in debug mode if the proxy string is empty.
Implementation
static CustomProxy? fromString({required String proxy}) {
// Check if the proxy string is empty
if (proxy.isEmpty) {
assert(
false,
'Proxy string passed to CustomProxy.fromString() is invalid.',
);
return null;
}
// Split the proxy string into parts and extract the IP address and port number if available
// Format: "ipAddress:port"
final proxyParts = proxy.split(':');
final ipAddress = proxyParts[0];
final port = proxyParts.isNotEmpty ? int.tryParse(proxyParts[1]) : null;
return CustomProxy(ipAddress: ipAddress, port: port);
}