locate 1.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 79

locate #

A Flutter plugin to work with Android Location Services(GPS/ Network).

usage #

This flutter plugin can be used on Android for fetching Location Data using either Google Play Services based Location or LocationManager based Location.

Well this plugin is has androidX support enabled.

Even you can specify whether to use Network provider or GPS provider as Location Data Provider.

Don't forget to add following permission in you AndroidManifest.xml.

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

If you're planning to use Google Play Services based FusedLocationProvider, request for ACCESS_FINE_LOCATION.

Otherwise you may only request for ACCESS_COARSE_LOCATION.

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

how to use API #

Get an intance of Locate class.

var _locate = Locate();

Make sure you first request for Location Permission from user.

_locate.requestLocationPermission().then((bool result) {
                  if (result)
                    // we're good to go
                    // you may be interested in letting user know about it, that location access permission is required

Now time to enable Location.

_locate.enableLocation().then((bool result) {
                      if (result) {
                        // setState(() => _areWeGettingLocationUpdate = true);
                        // here you may be interested in updating UI and the request for location Data.
                        // Location data will be fetched and delivered as Stream<MyLocation>
                        // user didn't enable location

And finally, let's request for getting Location Data Feed.

                            // we listen for location data, which is received as stream
                            (MyLocation data) =>
                                setState(() => _locationData.add(data)), // as soon as data received,will update UI/ perform some other task using location data.
                            cancelOnError: true, // if some error occurs, Stream will be closed
                            onError: (e) => print(e), // error is displayed

Aah I just forgot to mention one thing, how to stop listening location update.

_locate.stopLocationDataFeed().then((bool result) {
  // do some UI updation kind of work/ or something else

what's MyLocation #

MyLocation class can be thought of as a Location Data Container.

/// constructor of MyLocation
      this.time, // in DateTime
      this.altitude, // in meters
      this.bearing, // in degree
      this.speed, // in meters/s
      this.accuracy, // in meters
      this.verticalAccuracy, // in meters
      this.bearingAccuracy, // in meters
      this.speedAccuracy, // in meters/s
      this.provider, // as String,either gps/ network/ fused

I've added some companion methods which can be used from MyLocation, such as

// will fetch you name of direction of movement from bearing value

// m/s to km/h converion for speedaccuracy

/// same as above, but works on speed

/// displays time in pretty format

important points #

You can also set some optional named parameters while invoking methods from Locate class.

In case of following method, you can also set provider, to be LocationProvider.Network, if you want to use Network based Location only.

      {String provider: LocationProvider.GPS}); // default value is LocationProvider.GPS

Before requesting Location Data Feed, you can also set via which location manager to fetch data and location data provider name.

Note:: If you are planning use LocationServiceProvider.GMSBasedLocation, for fetching data, make sure you've requested for permission of accessing FINE Location. And also use LocationProvider.GPS as locationProvider parameter's value.

Otherwise while using LocationServiceProvider.LocationManagerBasedLocation as locationServiceProvider, you may either use LocationProvider.GPS or LocationProvider.Network, depending upon your requested permissions.

      {String locationServiceProvider:
      String locationProvider: LocationProvider.GPS});

If you've FINE Location access permission, you can simply request for Network Provider based location data.

Hope it was helpful.

Show some <3, to this venture, by putting star on GitHub.

1.0.0 #

This is the very first release of locate flutter plugin. It simply fetches android location data using either Google Play Service based Location Service or android.location.LocationManager. It can continously report device location using callback mechanism, which might be used to update UI.

This plugin only works for Androd Platform. Built with latest version of SDK(28).

1.1.0 #

Very happy to release a new version of this plugin.

In this release locate, tries to leverage the power of Asynchronous Programming, based on Future

If you've been using it, we'll this might be a bad situttion, but it's a breaking update.

API has been updated, for ease of usability. No callbacks anymore for receiving location data feed, a Stream

Hope it'll be helpful.


import 'package:flutter/material.dart';
import 'package:locate/locate.dart';
import 'package:locate/my_location.dart';
import 'package:flutter/services.dart' show SystemChrome;

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

class MyApp extends StatelessWidget {
  Widget build(BuildContext context) => MaterialApp(
        theme: ThemeData(
          textTheme: TextTheme(
            title: TextStyle(
              color: Colors.cyanAccent,
            subtitle: TextStyle(
              color: Colors.cyan,
          accentIconTheme: IconThemeData(
            color: Colors.cyanAccent,
          floatingActionButtonTheme: FloatingActionButtonThemeData(
            backgroundColor: Colors.black,
          iconTheme: IconThemeData(
            color: Colors.cyanAccent,
          appBarTheme: AppBarTheme(
              color: Colors.black45,
              actionsIconTheme: IconThemeData(
                color: Colors.red,
              textTheme: TextTheme(
                  title: TextStyle(
                color: Colors.tealAccent,
                fontSize: 20,
                letterSpacing: 2,
                fontWeight: FontWeight.bold,
              iconTheme: IconThemeData(
                color: Colors.red,
          scaffoldBackgroundColor: Colors.black45,
        title: 'Locate',
        home: MyHome(),

class MyHome extends StatefulWidget {
  _MyHomeState createState() => _MyHomeState();

class _MyHomeState extends State<MyHome> with TickerProviderStateMixin {
  Locate _locate; // main entry point for retrieving location data
      _areWeGettingLocationUpdate; // holds state information, helps to change widget appearance and behaviour
  List<MyLocation> _locationData;

  void initState() {
    _locate = Locate();
    _areWeGettingLocationUpdate = false;
    _locationData = [];

  void dispose() {

  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        title: const Text(
          textScaleFactor: 1.5,
        actions: <Widget>[
              icon: Icon(Icons.restore),
              onPressed: () => setState(() => _locationData = [])),
      body: _areWeGettingLocationUpdate
          ? _locationData.length == 0
              ? Center(
                  child: LinearProgressIndicator(
                    backgroundColor: Colors.black45,
                        Tween<Color>(begin: Colors.cyanAccent, end: Colors.cyan)
                        vsync: this,
              : ListView.builder(
                  itemBuilder: (context, index) => ListTile(
                        title: Text(
                          '${_locationData[index].longitude.roundToDouble()}, ${_locationData[index].latitude.roundToDouble()} with altitude ${_locationData[index].altitude} m',
                          style: TextStyle(
                            color: Colors.cyanAccent,
                        subtitle: Text(
                          '${_locationData[index].getParsedTimeString()} from ${_locationData[index].provider.toUpperCase()}',
                          style: TextStyle(
                            color: Colors.cyanAccent,
                        leading: Icon(
                          color: Colors.cyanAccent,
                  itemCount: _locationData.length,
                  padding: EdgeInsets.only(
                    top: 12,
                    bottom: 12,
                    left: 4,
                    right: 4,
          : Center(
              child: Row(
                mainAxisSize: MainAxisSize.min,
                children: <Widget>[
                    ' No Incoming Location Data Feed',
                    style: TextStyle(color: Colors.cyanAccent),
      floatingActionButton: Builder(
        builder: (BuildContext ctx) {
          return FloatingActionButton(
            onPressed: () {
              if (!_areWeGettingLocationUpdate)
                _locate.requestLocationPermission().then((bool result) {
                  if (result)
                    _locate.enableLocation().then((bool result) {
                      if (result) {
                        setState(() => _areWeGettingLocationUpdate = true);
                            (MyLocation data) =>
                                setState(() => _locationData.add(data)),
                            cancelOnError: true,
                            onError: (e) => print(e),
                _locate.stopLocationDataFeed().then((bool result) =>
                    setState(() => _areWeGettingLocationUpdate = false));
            child: _areWeGettingLocationUpdate
                ? Icon(
                    color: Colors.red,
                : Icon(
                    color: Colors.cyanAccent,
            elevation: 12,
                _areWeGettingLocationUpdate ? 'Stop Location' : 'Get Location',

Use this package as a library

1. Depend on it

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

  locate: ^1.1.0

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:locate/locate.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

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

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Health suggestions

Format lib/my_location.dart.

Run flutter format to format lib/my_location.dart.

Maintenance suggestions

The package description is too short. (-4 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies