isLocalhostUrl function
Check if a URL points to localhost.
Implementation
bool isLocalhostUrl(String url) {
try {
final uri = Uri.parse(url);
final host = uri.host.toLowerCase();
return host == 'localhost' ||
host == '127.0.0.1' ||
host == '::1' ||
host == '[::1]' ||
RegExp(r'^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$').hasMatch(host);
} catch (_) {
return false;
}
}