gpslocator 0.1.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 56

gpslocator #

A new flutter plugin for getting for location tracking

Getting Started #

Importing #


import 'package:gpslocator/GpsLocator.dart';


final GpsLocator gpsLocator = new GpsLocator();

Checking Permissions #


 await gpsLocator.checkPermission.then((permission){
      if (permission){

      //Permission is Already Granted 

      }else{

         gpsLocator.handlePermission('com.example.gpslocator_example');
     
      }
    });

Asking for permission #

         gpsLocator.handlePermission('com.example.gpslocator_example');

  This handlePermission function takes a parameter of package name and asks for 
  location permission  

Checking wheather location is active #


  await gpsLocator.isGpsActive.then((isActive)  {
          if (isActive){
              
              //location is Active
          }
           
        });

Starting Location Stream #

Location stream should be started before listening/subscribing to it

Normal
             await gpsLocator.startStream();

Configured
   
    await gpsLocator.startStream(interval: 1000,fastestInterval: 5000,priority: GPSPriority.BALANCED_POWER_ACCURACY);

Recommended way to start the stream ( just wheather permission and location is enabled )


await gpsLocator.checkPermission.then((permission) async {
      if (permission){

await gpsLocator.isGpsActive.then((isActive) async {

          if (isActive){
    
             await gpsLocator.startStream();
         
          }
        });
      }else{
        
      gpsLocator.handlePermission('com.example.gpslocator_example');

      }
        
    });


Stoping Location Stream #


 await gpsLocator.stopStream;

Getting the last location #


    await gpsLocator.lastLocation.then((lastLocation){
        //Last location  as Map
                  });

example

0.1.2 #

gpslocator #

A new flutter plugin for getting for location tracking

Getting Started #

Importing #


import 'package:gpslocator/GpsLocator.dart';


final GpsLocator gpsLocator = new GpsLocator();

Getting the last location #


    await gpsLocator.lastLocation.then((lastLocation){
        //Last location  as Map
                  });

Checking Permissions #


 await gpsLocator.checkPermission.then((permission){
      if (permission){

      //Permission is Already Granted 

      }else{

         gpsLocator.handlePermission('com.example.gpslocator_example');
     
      }
    });

Asking for permission #

         gpsLocator.handlePermission('com.example.gpslocator_example');

  This handlePermission function takes a parameter of package name and asks for 
  location permission  

Checking wheather location is active #


  await gpsLocator.isGpsActive.then((isActive)  {
          if (isActive){
              
              //location is Active
          }
           
        });

Starting Location Stream #

Location stream should be started before listening/subscribing to it

Normal
             await gpsLocator.startStream();

Configured
   
    await gpsLocator.startStream(interval: 1000,fastestInterval: 5000,priority: GPSPriority.BALANCED_POWER_ACCURACY);

Stoping Location Stream #


 await gpsLocator.stopStream;

example

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:gpslocator/GpsLocator.dart';

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

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  Location  test = Location(accuracy: 0,latitude: 0,longitude:0);
  bool canStart = false;
  final GpsLocator gpsLocator = new GpsLocator();
  @override
  void initState() {
    super.initState();

    superInit();
  }

  void superInit() async {
    await gpsLocator.checkPermission.then((permission) async {
      if (permission){
await gpsLocator.isGpsActive.then((isActive) async {
          if (isActive){
 await gpsLocator.startStream().then((r) {
              setState(() {
                this.canStart = r;
                print("-------------------  " + r.toString());
              });
            });
          }
           
        });
      }else{
        print("Permission : "+ permission.toString());
      gpsLocator.handlePermission('com.example.gpslocator_example');
      }
        
    });
         await gpsLocator.lastLocation.then((ll){
                    setState(() {
                      this.test = ll ;
                    });
                  });
  }



  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('GpsLocator app'),

        ),
        body: Stack(
                  children:[
                    Image.asset('assets/W.jpg',fit: BoxFit.cover,),
                     Column(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: <Widget>[
              Text("Location Stream ",),
              StreamBuilder<Location>(
                stream: gpsLocator.locationStream,
                builder: (BuildContext context, AsyncSnapshot<Location> snashot) {
                  if (!snashot.hasData)
                    return Center(child: CircularProgressIndicator());
                  return Row(
                    mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                    children: <Widget>[
                      Text(snashot.data.latitude.toString(),style:TextStyle(fontFamily: 'Raleway',fontSize: 20,color: Colors.white),),
                      Text(snashot.data.longitude.toString(),style:TextStyle(fontFamily: 'Raleway',fontSize: 20,color: Colors.white)),
                      Text(snashot.data.accuracy.toString().substring(0,4),style:TextStyle(fontFamily: 'Raleway',fontSize: 20,color: Colors.white))
                    ],
                  );
                },
              ),
              SizedBox(height:20),
              Text("Last  Location",),
              Row(
                    mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                    children: <Widget>[
                     
                      Text(test.latitude.toString(),style:TextStyle(fontFamily: 'Raleway',color: Colors.white),),
                      
                      Text(test.longitude.toString(),style:TextStyle(fontFamily: 'Raleway',color: Colors.white)),
                      
                      Text(test.accuracy.toString(),style:TextStyle(fontFamily: 'Raleway',color: Colors.white))
                    
                    ],
                  ),
             
            ],
          ),]
        ),
      floatingActionButton: FloatingActionButton(
        child: const Icon(Icons.location_on),
        onPressed: () async {
                 await gpsLocator.lastLocation.then((ll){
                    setState(() {
                      this.test = ll ;
                    });
                  });
                }
      ),
      ),

    );
  }

  void _stopStream() async {
    await gpsLocator.stopStream;
  }

  @override
  void dispose() {
    _stopStream();
    super.dispose();
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  gpslocator: ^0.1.2

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support 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:gpslocator/GpsLocator.dart';
import 'package:gpslocator/gpslocatorN.dart';
import 'package:gpslocator/gpslocatora.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
12
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
56
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.14
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform ios

Because:

  • package:gpslocator/GpsLocator.dart that imports:
  • package:gpslocator/gpslocatorN.dart that imports:
  • package:android_intent/android_intent.dart that declares support for platforms: android

Package does not support Flutter platform linux

Because:

  • package:gpslocator/GpsLocator.dart that declares support for platforms: android, ios

Package does not support Flutter platform macos

Because:

  • package:gpslocator/GpsLocator.dart that declares support for platforms: android, ios

Package does not support Flutter platform web

Because:

  • package:gpslocator/GpsLocator.dart that declares support for platforms: android, ios

Package does not support Flutter platform windows

Because:

  • package:gpslocator/GpsLocator.dart that declares support for platforms: android, ios

Package not compatible with SDK dart

Because:

  • gpslocator that is a package requiring null.

Health suggestions

Format lib/GpsLocator.dart.

Run flutter format to format lib/GpsLocator.dart.

Format lib/gpslocatora.dart.

Run flutter format to format lib/gpslocatora.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
android_intent ^0.3.6+1 0.3.7+2
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.2
platform 2.2.1
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test