With country_ip
you can find users' country (and nothing else) from their IP address.
This package is based on country.is. No API_KEY or AUTHORIZATION needed. Free to use API.
- Find users' country using their current IP
- Find country of a specified IP (Both IPv4 & IPv6 addresses supported)
To use this plugin, add country_ip
as a dependency in your pubspec.yaml file.
dependencies:
country_ip: [latest-version]
import 'package:country_ip/country_ip.dart';
To find users' country from their current IP, call CountryIp.find()
Returns CountryResponse
object which includes:
- IP
- Country
- Country Code (ISO 3166 ALPHA-2)
On Error functions returns null object.
Example :
final countryIpResponse = await CountryIp.find();
print("countryIpResponse : $countryIpResponse");
// countryIpResponse : CountryResponse(country: United States, countryCode: US, ip: 9.9.9.9)
print("User's country code : ${countryIpResponse?.countryCode}");
// User's country code : US
print("User's country : ${countryIpResponse?.country}");
// User's country : United States
print("User's ip : ${countryIpResponse?.ip}");
// User's ip : 9.9.9.9
To find country of a specified IP, call CountryIp.findFromIP(String ip)
Returns CountryResponse
object which includes:
- IP
- Country
- Country Code (ISO 3166 ALPHA-2)
On Error functions returns null object.
Examples :
- Using IPv4
final countryIpResponse = await CountryIp.findFromIP('9.9.9.9');
print("countryIpResponse : $countryIpResponse");
// countryIpResponse : CountryResponse(country: United States, countryCode: US, ip: 9.9.9.9)
print("User's country code : ${countryIpResponse?.countryCode}");
// User's country code : US
print("User's country : ${countryIpResponse?.country}");
// User's country : United States
print("User's ip : ${countryIpResponse?.ip}");
// User's ip : 9.9.9.9
- Using IPv6
final countryIpResponse = await CountryIp.findFromIP('::ffff:909:909');
print("countryIpResponse : $countryIpResponse");
// countryIpResponse : CountryResponse(country: United States, countryCode: US, ip: ::ffff:909:909)
print("User's country code : ${countryIpResponse?.countryCode}");
// User's country code : US
print("User's country : ${countryIpResponse?.country}");
// User's country : United States
print("User's ip : ${countryIpResponse?.ip}");
// User's ip : ::ffff:909:909
Please file any issues, bugs or feature requests as an issue on our GitHub page.
This Country IP package is developed by NirmalCode.