ip_geolocation_api_mtec 0.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 54

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_mtec/ip_geolocation_api_mtec.dart';

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

class MyApp extends StatelessWidget {

    @override
    Widget build(BuildContext context) {
        return MaterialApp(
            debugShowCheckedModeBanner: false,
            title: 'Geolocation Demo',
            home: HomePage(),
        );
    }
}

class HomePage extends StatefulWidget{

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

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

    @override
    void initState() {
        super.initState();
        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(
                                child: Text('toJSON'),
                                onPressed: (){
                                    if ( geolocationData==null ) return;
                                    setState(() {
                                        text = jsonEncode(geolocationData.toJson());
                                    });
                                }, 
                            ),
                        ],
                    ),
                ),
            ),
        );
    }
}

[0.0.1] #

- Initial release.

example/lib/main.dart

import 'dart:convert';

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

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

class MyApp extends StatelessWidget {

    @override
    Widget build(BuildContext context) {
        return MaterialApp(
            debugShowCheckedModeBanner: false,
            title: 'Hola page',
            home: HomePage(),
        );
    }
}

class HomePage extends StatefulWidget{

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

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

    @override
    void initState() {
        super.initState();
        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(
                                child: Text('toJSON'),
                                onPressed: (){
                                    if ( geolocationData==null ) return;
                                    setState(() {
                                        text = jsonEncode(geolocationData.toJson());
                                    });
                                }, 
                            ),
                        ],
                    ),
                ),
            ),
        );
    }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  ip_geolocation_api_mtec: ^0.0.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:ip_geolocation_api_mtec/ip_geolocation_api_mtec.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
12
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
54
Learn more about scoring.

We analyzed this package on Jul 11, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.15

Analysis suggestions

Package not compatible with SDK dart

Because:

  • ip_geolocation_api_mtec that is a package requiring null.

Health issues and suggestions

Document public APIs. (-1 points)

14 out of 14 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Format lib/ip_geolocation_api_mtec.dart.

Run flutter format to format lib/ip_geolocation_api_mtec.dart.

Format lib/src/api.dart.

Run flutter format to format lib/src/api.dart.

Format lib/src/models/geolocation_data.dart.

Run flutter format to format lib/src/models/geolocation_data.dart.

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
http ^0.12.1 0.12.1
meta ^1.1.8 1.2.2 1.3.0-nullsafety
Transitive dependencies
charcode 1.1.3
collection 1.14.13 1.15.0-nullsafety
http_parser 3.1.4
path 1.7.0
pedantic 1.9.2
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.2.0 1.3.0-nullsafety
Dev dependencies
flutter_test