watch_ip_sdk 0.1.1
watch_ip_sdk: ^0.1.1 copied to clipboard
Official Dart/Flutter SDK for the Watch-IP visitor geolocation API (GET /v1/geo).
example/watch_ip_sdk_example.dart
// ignore_for_file: avoid_print
import 'package:watch_ip_sdk/watch_ip_sdk.dart';
Future<void> main() async {
// The API key is a publishable key meant to ship in client-side code — see
// https://watch-ip.com/docs for the origin-locking model this relies on.
final client = WatchIP('wip_pub_xxxxxxxx');
try {
final geo = await client.getGeo();
print('${geo.country} ${geo.city} ${geo.timezone}');
if (geo.security.isVpn || geo.security.isTor) {
print('Visitor is connecting through a VPN or Tor.');
}
} on WatchIPError catch (e) {
// e.g. "origin_not_allowed" 403 "This origin is not authorized for this API key."
print(
'Watch-IP request failed: ${e.code} (status ${e.status}): ${e.message}');
}
// Or, for a one-off call without holding onto a client instance:
final geo = await getGeo('wip_pub_xxxxxxxx', include: ['hostname']);
print(geo.hostname);
}