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.
Features
- Find users' country using their current IP
- Find country of a specified IP (Both IPv4 & IPv6 addresses supported)
Getting started
To use this plugin, add country_ip
as a dependency in your pubspec.yaml file.
dependencies:
country_ip: [latest-version]
Usage
Import
import 'package:country_ip/country_ip.dart';
Find country using current IP
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
Find country of a specified IP
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
Issues
Please file any issues, bugs or feature requests as an issue on our GitHub page.
Author
This Country IP package is developed by NirmalCode.