ip_geolocation 1.0.0 copy "ip_geolocation: ^1.0.0" to clipboard
ip_geolocation: ^1.0.0 copied to clipboard

A dart package to flutter or dart projects to get your geolocation data from your IP, updated from Darwin Morocho's contribution.

ip-geolocation #

A dart package to get your geolocation data from your IP

Example #

import 'dart:convert';

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

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

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: HomePage(),
    );
  }
}

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

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

class _HomePageState extends State<HomePage> {
  String text = '';
  GeolocationData geolocationData;

  @override
  void initState() {
    super.initState();
    this.getIp();
  }

  Future<void> getIp() async {
    geolocationData = await GeolocationAPI.getData();
    if (geolocationData != null) {
      setState(() {
        text = geolocationData.ip;
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Container(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text(text),
              FlatButton(
                  onPressed: () {
                    if (geolocationData != null) {
                      setState(() {
                        text = jsonEncode(geolocationData.toJson());
                      });
                    }
                  },
                  child: Text("toJSON"))
            ],
          ),
        ),
      ),
    );
  }
}
4
likes
120
pub points
74%
popularity

Publisher

unverified uploader

A dart package to flutter or dart projects to get your geolocation data from your IP, updated from Darwin Morocho's contribution.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

http, meta

More

Packages that depend on ip_geolocation