gps_service_plugin 0.0.2 copy "gps_service_plugin: ^0.0.2" to clipboard
gps_service_plugin: ^0.0.2 copied to clipboard

Gps Service Flutter plugin.

example/lib/main.dart

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

import 'package:gps_service_plugin/gps_manager.dart';

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

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

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

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    print('Initializing...');
    GpsManager.initialize(callback);
    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');
  }

  @override
  void dispose() {
    GpsManager.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Column(
          children: <Widget>[
            Container(
              margin: EdgeInsets.only(left: 16, right: 16),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: <Widget>[
                	Text("is trecking location:"),
                  Switch(
                    value: _switchOn,
                    onChanged: (value) {
                      if (value) {
                        GpsManager.startListeningLocation();
                      } else {
                        GpsManager.stopListeningLocation();
                      }
                      setState(() => _switchOn = value);
                    },
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}
0
likes
20
pub points
0%
popularity

Publisher

unverified uploader

Gps Service Flutter plugin.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on gps_service_plugin