queryOwnIp static method
Query your own public IP address as a string.
Optionally specify the response format (defaults to text).
final ip = await IpQuery.queryOwnIp();
print('My IP: $ip');
Implementation
static Future<String> queryOwnIp(
{IpQueryFormat format = IpQueryFormat.text}) async {
final response = await http
.get(Uri.parse(_baseUrl + '?format=${_formatToString(format)}'));
if (response.statusCode != 200) {
throw Exception('Failed to fetch own IP: ${response.statusCode}');
}
return response.body.trim();
}