background_locations 0.0.3+1

  • Readme
  • Changelog
  • Example
  • Installing
  • 42

background_locations #

This plugin still under development, not recommended for production use.

Inspired from "flutter_background_geolocation" plugin.

Currently available only for Android

Getting Started #

This project is a starting point for a Flutter plug-in package, a specialized package that includes platform-specific implementation code for Android and/or iOS.

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

0.0.3+1 #

bug fix

0.0.3 #

gps status change listener

0.0.2+14 #

bug fix

0.0.2+13 #

bug fix - setConfig not get updated

0.0.2+12 #

bug fix - setConfig not get updated

0.0.2+11 #

bug fix

0.0.2+10 #

bug fix

0.0.2+9 #

bug fix

0.0.2+8 #

bug fix

0.0.2+7 #

bug fix

0.0.2+6 #

bug fix

0.0.2+5 #

bug fix

0.0.2+4 #

bug fix

0.0.2+3 #

bug fix

0.0.2+2 #

bug fix

0.0.2+1 #

bug fix

0.0.2 #

writes location updates to firebase location accuracy improvements

0.0.1+14 #

add disable foreground service button to notification removed notification sound

0.0.1+13 #

get provider/gps state

0.0.1+12 #

service icon fix

0.0.1+11 #

get current position fix

0.0.1+10 #

set odometer fix get current position fix

0.0.1+9 #

set odometer fix

0.0.1+8 #

set odometer

0.0.1+7 #

fix get current position

0.0.1+6 #

fix get current position

0.0.1+5 #

bug fix get current position

0.0.1+4 #

bug fix get current position

0.0.1+3 #

get current position

0.0.1+2 #

start, stop background locations calculate odometer

example/lib/main.dart

import 'dart:async';

import 'package:background_locations/background_locations.dart' as bg;
import 'package:flutter/material.dart';

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

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

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  bool _moving = false;
  String _odometer = '0.0';
  String _location = '-';
  String _providerState = 'unknown';

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.
//    try {
//      platformVersion = await bg.BackgroundLocation.platformVersion;
//    } on PlatformException {
//      platformVersion = 'Failed to get platform version.';
//    }

    // 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(() {
      _platformVersion = platformVersion;
    });

    bg.BackgroundLocation.onLocation((loc) async {
      print('onLocation');
      _odometer = (await bg.BackgroundLocation.odometer).toString();
      setState(() {});
    });

    bg.BackgroundLocation.onMotionChange((val) {
      setState(() {
        _moving = val;
      });
    });

    bg.BackgroundLocation.onProviderChange((val) {
      print(val.toString());
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: SingleChildScrollView(
          child: Column(
            mainAxisSize: MainAxisSize.max,
            children: <Widget>[
              RaisedButton(
                  child: Text('Ready'),
                  onPressed: () async {
                    var state = await bg.BackgroundLocation.ready(bg.Config(
                      enableHeadless: true,
                    ));

                    print(state.toString());
                  }),
              RaisedButton(
                child: Text('start'),
                onPressed: () async {
                  var state = await bg.BackgroundLocation.ready(bg.Config(
                    enableHeadless: true,
                    firebaseConfig: bg.FirebaseConfig(
                        appName: 'test',
                        apiKey: 'XXXXXXXXXXXXXX',
                        applicationId: '00000000000',
                        databaseRefPaths: [
                          bg.DatabaseRefPath(
                              path: 'test/1/location',
                              method: bg.DatabaseRefPath.UPDATE_METHOD_VALUE),
                          bg.DatabaseRefPath(
                              path: 'test/1/trip/1/path',
                              method: bg.DatabaseRefPath.UPDATE_METHOD_ADD),
                        ],
                        databaseUrl: 'https://[project].firebaseio.com',
                        email: 'test@pml.com',
                        password: 'test@pml'),
                  ));

                  print(state.toString());
                  await bg.BackgroundLocation.start();
                },
              ),
              RaisedButton(
                child: Text('stop'),
                onPressed: () async {
                  await bg.BackgroundLocation.stop();
                },
              ),
              RaisedButton(
                child: Text('current location'),
                onPressed: () async {
                  var loc = await bg.BackgroundLocation.getCurrentPosition();
                  setState(() {
                    _location = loc.toString();
                  });
                },
              ),
              Text('ODOMETER $_odometer'),
              Text(
                'MOVING',
                style: TextStyle(
                  backgroundColor: _moving ? Colors.green : Colors.orange,
                  color: Colors.white,
                ),
              ),
              Text('LOCATION $_location'),
              SizedBox(height: 16.0),
              Text('$_providerState'),
              RaisedButton(
                child: Text('Check Provider State'),
                onPressed: () {
                  bg.BackgroundLocation.providerState.then((val) {
                    setState(() {
                      _providerState = val.toString();
                    });
                  });
                },
              )
            ],
          ),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  background_locations: ^0.0.3+1

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

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

  • Dart: 2.8.4
  • pana: 0.13.13
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform ios

Because of import path [package:background_locations/background_locations.dart] that declares support for platforms: android

Package does not support Flutter platform linux

Because of import path [package:background_locations/background_locations.dart] that declares support for platforms: android

Package does not support Flutter platform macos

Because of import path [package:background_locations/background_locations.dart] that declares support for platforms: android

Package does not support Flutter platform web

Because of import path [package:background_locations/background_locations.dart] that declares support for platforms: android

Package does not support Flutter platform windows

Because of import path [package:background_locations/background_locations.dart] that declares support for platforms: android

Package not compatible with SDK dart

because of import path [background_locations] that is in a package requiring null.

Health suggestions

Fix lib/background_location.dart. (-1.49 points)

Analysis of lib/background_location.dart reported 3 hints:

line 123 col 29: The value of the field '_eventChannelHttp' isn't used.

line 150 col 28: The value of the field '_eventsHttp' isn't used.

line 151 col 24: The value of the field '_eventsSchedule' isn't used.

Format lib/models/firebase_config.dart.

Run flutter format to format lib/models/firebase_config.dart.

Maintenance issues and suggestions

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

At the time of the analysis the homepage field https://gitlab.com/libraries-sync/flutter_background_locations 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.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
device_info ^0.4.1+4 0.4.2+4
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.1
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8
Dev dependencies
flutter_test