country_ip 3.0.0 copy "country_ip: ^3.0.0" to clipboard
country_ip: ^3.0.0 copied to clipboard

Package to find users' country from their IP. Dart package based on country API.

pub package BSD-3-Clause License

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.

14
likes
160
points
4.5k
downloads

Publisher

verified publishernirmalcode.com

Weekly Downloads

Package to find users' country from their IP. Dart package based on country API.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

http

More

Packages that depend on country_ip