background_location_service 0.0.6 copy "background_location_service: ^0.0.6" to clipboard
background_location_service: ^0.0.6 copied to clipboard

discontinued
outdated

A Flutter plugin to get location updates even when application is not in foreground.

example/lib/main.dart

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

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

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

class _MyAppState extends State<MyApp> {
  String latitude = "waiting...";
  String longitude = "waiting...";
  String altitude = "waiting...";
  String accuracy = "waiting...";
  String bearing = "waiting...";

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

    BackgroundLocationService.startLocationService();
    BackgroundLocationService.getLocationUpdates((location) {
      setState(() {
        this.latitude = location.latitude.toString();
        this.longitude = location.longitude.toString();
        this.accuracy = location.accuracy.toString();
        this.altitude = location.altitude.toString();
        this.bearing = location.bearing.toString();
      });

      print("Latitude: " + latitude);
      print("Longitude: " + longitude);
      print("Altitude: " + altitude);
      print("Accuracy: " + accuracy);
      print("Bearing: " + bearing);
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Background Location Service'),
        ),
        body: Center(
          child: ListView(
            children: <Widget>[
              locationData("Latitude: " + latitude),
              locationData("Longitude: " + longitude),
              locationData("Altitude: " + altitude),
              locationData("Accuracy: " + accuracy),
              locationData("Bearing: " + bearing),
              RaisedButton(
                  onPressed: () {
                    BackgroundLocationService.startLocationService();
                  },
                  child: Text("Start Location Service")),
              RaisedButton(
                  onPressed: () {
                    BackgroundLocationService.stopLocationService();
                  },
                  child: Text("Stop Location Service")),
              RaisedButton(
                  onPressed: () {
                    getCurrentLocation();
                  },
                  child: Text("Get Current Location")),
            ],
          ),
        ),
      ),
    );
  }

  Widget locationData(String data) {
    return Text(
      data,
      style: TextStyle(
        fontWeight: FontWeight.bold,
        fontSize: 18,
      ),
      textAlign: TextAlign.center,
    );
  }

  getCurrentLocation() {
    BackgroundLocationService().getCurrentLocation().then((location) {
      print("This is current Location" + location.longitude.toString());
    });
  }

  @override
  void dispose() {
    BackgroundLocationService.stopLocationService();
    super.dispose();
  }
}
0
likes
0
pub points
0%
popularity

Publisher

unverified uploader

A Flutter plugin to get location updates even when application is not in foreground.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on background_location_service