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

PlatformAndroid

Localizacion en tiempo real

example/lib/main.dart

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

import 'package:flutter/services.dart';
import 'package:pgjuvenal/pgjuvenal.dart';

void main() {
  runApp(MyApp());
}

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

class _MyAppState extends State<MyApp> {
  List<String> keysRetrieved = [];

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String pathToReference = "Sites";

    //Intializing Pgjuvenal
    Pgjuvenal.initialize(pathToReference);

    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      Pgjuvenal.queryAtLocation(30.730743, 76.774948, 5)!.listen((map) {
        print(map);
        if (map != null) {
          var callBack = map['callBack'];

          //latitude will be retrieved from map['latitude']
          //longitude will be retrieved from map['longitude']

          switch (callBack) {
            case Pgjuvenal.onKeyEntered:
              keysRetrieved.add(map["key"]);
              break;

            case Pgjuvenal.onKeyExited:
              keysRetrieved.remove(map["key"]);
              break;

            case Pgjuvenal.onKeyMoved:
//              keysRetrieved.add(map[callBack]);
              break;

            case Pgjuvenal.onGeoQueryReady:
//              map["result"].forEach((key){
//                keysRetrieved.add(key);
//              });

              break;
          }
        }

        setState(() {});
      }).onError((error) {
        print(error);
      });
    } on PlatformException {
//      response = '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;
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
          appBar: AppBar(
            title: const Text('Plugin example app'),
          ),
          body: Column(
            children: <Widget>[
              Padding(
                padding: EdgeInsets.all(20.0),
              ),
              Center(
                child: keysRetrieved.length > 0
                    ? Text("First key is " +
                    keysRetrieved.first.toString() +
                    "\nTotal Keys " +
                    keysRetrieved.length.toString())
                    : CircularProgressIndicator(),
              ),
              Padding(
                padding: EdgeInsets.all(10.0),
              ),
              Center(
                child: RaisedButton(
                  onPressed: () {
                    setLocation();
                  },
                  color: Colors.blueAccent,
                  child: Text(
                    "Set Location",
                    style: TextStyle(color: Colors.white),
                  ),
                ),
              ),
              Padding(
                padding: EdgeInsets.all(10.0),
              ),
              Center(
                child: RaisedButton(
                  onPressed: () {
                    setLocationFirst();
                  },
                  color: Colors.blueAccent,
                  child: Text(
                    "Set Location AsH28LWk8MXfwRLfVxgx",
                    style: TextStyle(color: Colors.white),
                  ),
                ),
              ),
              Padding(
                padding: EdgeInsets.all(10.0),
              ),
              Center(
                child: RaisedButton(
                  onPressed: () {
                    getLocation();
                  },
                  color: Colors.blueAccent,
                  child: Text(
                    "Get Location AsH28LWk8MXfwRLfVxgx",
                    style: TextStyle(color: Colors.white),
                  ),
                ),
              ),
              Padding(
                padding: EdgeInsets.all(10.0),
              ),
              Center(
                child: RaisedButton(
                  onPressed: () {
                    removeLocation();
                  },
                  color: Colors.blueAccent,
                  child: Text(
                    "Remove Location AsH28LWk8MXfwRLfVxgx",
                    style: TextStyle(color: Colors.white),
                  ),
                ),
              ),
              Padding(
                padding: EdgeInsets.all(10.0),
              ),
              // Center(
              //   child: RaisedButton(
              //     onPressed: () {
              //       initPlatformState();
              //     },
              //     color: Colors.blueAccent,
              //     child: Text(
              //       "Register Listener",
              //       style: TextStyle(color: Colors.white),
              //     ),
              //   ),
              // ),
              // Padding(
              //   padding: EdgeInsets.all(10.0),
              // ),
              Center(
                child: RaisedButton(
                  onPressed: () {
                    removeQueryListener();
                  },
                  color: Colors.blueAccent,
                  child: Text(
                    "Remove Query Listener",
                    style: TextStyle(color: Colors.white),
                  ),
                ),
              ),
            ],
          )),
    );
  }

  void setLocation() async {
    bool? response = await Pgjuvenal.setLocation(
        new DateTime.now().millisecondsSinceEpoch.toString(),
        30.730743,
        76.774948);

    print(response);
  }

  void setLocationFirst() async {
    bool? response =
    await Pgjuvenal.setLocation("AsH28LWk8MXfwRLfVxgx", 30.730743, 76.774948);

    print(response);
  }

  void removeLocation() async {
    bool? response = await Pgjuvenal.removeLocation("AsH28LWk8MXfwRLfVxgx");

    print(response);
  }

  void removeQueryListener() async {
    bool? response = await Pgjuvenal.stopListener();

    keysRetrieved.clear();
    setState(() {});

    print(response);
  }

  void getLocation() async {
    Map<String, dynamic> response =
    await Pgjuvenal.getLocation("AsH28LWk8MXfwRLfVxgx");

    print(response);
  }
}
0
likes
140
points
10
downloads

Publisher

unverified uploader

Weekly Downloads

Localizacion en tiempo real

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on pgjuvenal

Packages that implement pgjuvenal