ipapi 2.0.1

SDKdartflutter
Platformandroidioswindowslinuxmacosweb

Geolocation plugin for Flutter based on ip-api.com. Supports both free and pro access.

ipapi

Geolocation plugin for Flutter using IP-API.com's IP Geolocation API.

Features

  • Supports all platforms
  • Supports both free & pro access to IP-API.com
  • Free access does not require an API key.

Usage

To use this plugin, add ipapi as a dependency in your pubspec.yaml file.

Examples

Here are small examples that show you how to use the API.

// Obtain all available information for the current IP using the free API
final GeoData? geoData = await IpApi.getData("172.217.0.0");
print(geoData?.toJson());
/* Prints
{
    "query": "172.217.0.0",
    "status": "success",
    "continent": null, // optional field not included in request
    "continentCode": null, // optional field not included in request
    "country": "United States",
    "countryCode": "US",
    "region": "IL",
    "regionName": "Illinois",
    "city": "Chicago",
    "district": null, // optional field not included in request
    "zip": "60666",
    "lat": 41.8781,
    "lon": -87.6298,
    "timezone": "America/Chicago",
    "offset": null, // optional field not included in request
    "currency": null, // optional field not included in request
    "isp": "Google LLC",
    "org": "Google LLC",
    "as": "AS15169 Google LLC",
    "reverse": null, // optional field not included in request
    "asname": null, // optional field not included in request
    "mobile": null, // optional field not included in request
    "proxy": null, // optional field not included in request
    "hosting": null // optional field not included in request
}
*/

// Obtain all available information for an IP different to the current IP using the free API, using German language and querying selected fields only
final GeoData? geoData = await IpApi.getData({
    ip: '172.217.0.0',
    lang: 'de',
    fields: ['country'],
});
print(geoData?.country); // prints 'Vereinigte Staaten'
print(geoData?.city); // prints 'null' since field is not part of query

// Usage with API key automatically queries PRO API endpoint 'pro.ip-api.com'
final GeoData? geoData = await IpApi.getData({
    apiKey: 'xxxxxxxxxxxxxxx'
});

List of fields

namedescriptionexampletype
statussuccess or failsuccessstring?
messageIncluded only when status is fail. Can be one of the following: private range, reserved range, invalid queryinvalid querystring?
continentContinent nameNorth Americastring?
continentCodeTwo-letter continent codeNAstring?
countryCountry nameUnited Statesstring?
countryCodeTwo-letter country code ISO 3166-1 alpha-2USstring?
regionRegion/state short code (FIPS or ISO)CA or 10string?
regionNameRegion/stateCaliforniastring?
cityCityMountain Viewstring?
districtDistrict (subdivision of city)Old Farm Districtstring?
zipZip code94043string?
latLatitude37.4192double?
lonLongitude-122.0574double?
timezoneTimezone (tz)America/Los_Angelesstring?
offsetTimezone UTC DST offset in seconds-25200int?
currencyNational currencyUSDstring?
ispISP nameGooglestring?
orgOrganization nameGooglestring?
asAS number and organization, separated by space (RIR). Empty for IP blocks not being announced in BGP tables.AS15169 Google Inc.string?
asnameAS name (RIR). Empty for IP blocks not being announced in BGP tables.GOOGLEstring?
reverseReverse DNS of the IP (can delay response)wi-in-f94.1e100.netstring?
mobileMobile (cellular) connectiontruebool?
proxyProxy, VPN or Tor exit addresstruebool?
hostingHosting, colocated or data centertruebool?
queryIP used for the query173.194.67.94string?

Additional information

Please note the following important information

  • We are not associated with IP-API.com in any way. This plugin is simply a wrapper around the API provided by IP-API.com. We do not assume any liability that may arise from using this plugin or the IP-API.com.
  • Please note that the free version of IP-API.com's IP Geolocation API is limited to 45 requests per IP and minute and uses HTTP (not HTTPS) and may not be used for commercial purposes. Usage for commercial purposes requires a pro license.
  • Please make sure to read up on the full terms of use and up-2-date API specifications directly at https://ip-api.com.