Search packages, repositories and app categories

GitHub repositorydarwin-morocho/dart-ip-geolocation-api

dart-ip-geolocation-api

darwin-morocho/dart-ip-geolocation-api open-source repository details.

dart-ip-geolocation-api project cover
Stars
5
Forks
4
Last push (UTC)
Aug 31, 2020
Project status
Active

Original README

English project snapshot. Visit GitHub for the latest content.

ip_geolocation_api

A dart package to get your geolocation data from your IP

Example

import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:ip_geolocation_api/ip_geolocation_api.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"))
            ],
          ),
        ),
      ),
    );
  }
}
Darwin Morocho GitHub avatar
GitHub author

Darwin Morocho ↗

Native and cross-platform mobile developer.

LanguagesDartKotlinSwiftObjective-C

Packages published by this repository

Dependencies used

Dependency list 3 items

  • http^0.12.0+3
  • meta^1.1.8
  • flutter_testDevelopment{"sdk":"flutter"}

How do I choose a repository?

Start with your use case, compare repository activity, and check the original project before adopting it.

  1. Search by repository name, owner or description, then narrow the results by topic.
  2. Compare stars, forks and recent pushes. Stars show community interest, not a guarantee of quality.
  3. Read the README, license and issues on GitHub before using a project.

Sources and maintenance

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗