gps_service_plugin 0.0.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 46

Background location-tracking module for iOS and Android.

Installing the Plugin #

đź“‚ pubspec.yaml:

Note: See Versions for latest available version.

dependencies: flutter_background_geolocation: '^1.3.2'

Setup Guides #

Android #

It's required to request the ACCESS_FINE_LOCATION permission in AndroidManifest.xml:

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

Also add the following class in the same directory as and name it

public class Application extends FlutterApplication 
                         implements PluginRegistrantCallback {
  public void onCreate() {

  public void registerWith(PluginRegistry registry) {

The purpose of extending FlutterApplication is to set a reference to the application’s plugin registrant within GeofencingService. This is needed to register the application’s plugins with the geofencing plugin’s background isolate, which makes it possible to use other plugins in the context of that isolate.

Finally, set the following field in AndroidManifest.xml to use the new Application instead of the default FlutterApplication:


iOS #

Requesting the relevant permissions on iOS requires some simple modifications to Info.plist in the ios directory of the application. First, add the following lines to request background location updates:


Then set the NSLocation description messages:

  <string>YOUR DESCRIPTION HERE</string>
  <string>YOUR DESCRIPTION HERE</string>

These descriptions are shown to the user when the application requests access to their location. If they’re not provided, geofencing registration will fail silently!

import UIKit
import Flutter
import gps_service_plugin

@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    // Register the plugins with the AppDelegate
    // Set registerPlugins as a callback within GeofencingPlugin. This allows
    // for the Geofencing plugin to register the plugins with the background
    // FlutterEngine instance created to handle events. If this step is skipped,
    // other plugins will not work in the geofencing callbacks!
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)

func registerPlugins(_ registry: FlutterPluginRegistry) {
    GeneratedPluginRegistrant.register(with: registry)

Finally, set a reference to the application’s plugin registrant within SwiftGpsServicePlugin from the application’s AppDelegate. This is needed to register the application’s plugins with the geofencing plugin’s background isolate, which makes it possible to use other plugins in the context of that isolate.

Dart #

First of all initialize the plugin in initState with static callback function:

  static _onLocation({Position pos, String msg}) async {
    print('pos: $pos, msg: $msg');
  void initState() {

And don't forget to dispose it:

  void dispose() {

Then you can start and stop location tracking:

  void _startLocationTracking() async {
    final isTrackingLocation = await GpsManager.isTreckingLocation();
    if (!isTrackingLocation) {

  void _stopLocationTracking() async {
    final isTrackingLocation = await GpsManager.isTreckingLocation();
    if (isTrackingLocation) {

0.0.1 #

  • TODO: Describe initial release.


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

import 'package:gps_service_plugin/gps_manager.dart';

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

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

class _MyAppState extends State<MyApp> {
  bool _switchOn = false;

  void initState() {

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    print('Initialization done');
    final isTreckingLocation = await GpsManager.isTreckingLocation();

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;
    setState(() {
	    _switchOn = isTreckingLocation;

  static void callback({Position pos, String msg}) async {
    print('Callback, pos: ${pos?.toString()}');
    print('Callback, lat: ${pos?.lat}, lon: ${pos?.lon}, msg: $msg');

  void dispose() {

  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        body: Column(
          children: <Widget>[
              margin: EdgeInsets.only(left: 16, right: 16),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: <Widget>[
                	Text("is trecking location:"),
                    value: _switchOn,
                    onChanged: (value) {
                      if (value) {
                      } else {
                      setState(() => _switchOn = value);

Use this package as a library

1. Depend on it

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

  gps_service_plugin: ^0.0.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:gps_service_plugin/callback_dispatcher.dart';
import 'package:gps_service_plugin/generated/i18n.dart';
import 'package:gps_service_plugin/gps_manager.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 Jun 5, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.2
  • pana: 0.13.8-dev
  • Flutter: 1.17.1

Health suggestions

Format lib/callback_dispatcher.dart.

Run flutter format to format lib/callback_dispatcher.dart.

Format lib/generated/i18n.dart.

Run flutter format to format lib/generated/i18n.dart.

Format lib/gps_manager.dart.

Run flutter format to format lib/gps_manager.dart.

Maintenance issues and suggestions

Homepage URL doesn't exist. (-20 points)

At the time of the analysis the homepage field was unreachable.

The package description is too short. (-20 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 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.


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