geolocation_ip 0.0.3 copy "geolocation_ip: ^0.0.3" to clipboard
geolocation_ip: ^0.0.3 copied to clipboard

A Dart package leverages the IP-API.com service to provide geolocation data based on IP addresses.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:geolocation_ip/geolocation_ip.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Example',
      home: Home(),
    );
  }
}

class Home extends StatefulWidget {
  Home({Key? key}) : super(key: key);

  @override
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<Home> {
  LocationInfo? info;

  Future<void> getLocationInfo() async {
    String ip = '24.48.0.1';

    LocationInfo? locationInfo = await GeolocationIP.getInfo(ip, lang: Lang.en);

    print(locationInfo?.toJson());

    info = locationInfo;
    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              info?.toJson().toString() ?? '',
              textAlign: TextAlign.center,
            ),
            SizedBox(height: 18),
            MaterialButton(
              onPressed: getLocationInfo,
              child: Text("Get Location Info"),
            )
          ],
        ),
      ),
    );
  }
}
3
likes
160
pub points
58%
popularity

Publisher

verified publisherelriztechnology.com

A Dart package leverages the IP-API.com service to provide geolocation data based on IP addresses.

Repository (GitHub)
View/report issues

Topics

#ip-geolocation #geolocation #ip-api #location

Documentation

API reference

License

MIT (license)

Dependencies

http

More

Packages that depend on geolocation_ip