background_locations 0.0.1+12 copy "background_locations: ^0.0.1+12" to clipboard
background_locations: ^0.0.1+12 copied to clipboard

unlistedoutdated

A new Flutter plugin.

example/lib/main.dart

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

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

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 = '-';

  @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 {
      _odometer = (await bg.BackgroundLocation.odometer).toString();
      setState(() {});
    });

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Column(
          children: <Widget>[
            RaisedButton(
              child: Text('start'),
              onPressed: () async {
                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'),
          ],
        ),
      ),
    );
  }
}
1
likes
0
pub points
0%
popularity

Publisher

unverified uploader

A new Flutter plugin.

Repository (GitLab)
View/report issues

License

unknown (LICENSE)

Dependencies

device_info, flutter

More

Packages that depend on background_locations