flutter_geofire 0.0.4

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • new56

flutter_geofire

A Flutter plugin to use the GeoFire Api

For Flutter plugins for other products, see mrdishant@github

Note: This plugin is still under development, and some APIs might not be available yet. Feedback and Pull Requests are most welcome!

Usage

GeoFire — Realtime location queries with Firebase.

GeoFire is an open-source library that allows you to store and query a set of keys based on their geographic location.

At its heart, GeoFire simply stores locations with string keys. Its main benefit however, is the possibility of querying keys within a given geographic area - all in realtime.

GeoFire uses the Firebase database for data storage, allowing query results to be updated in realtime as they change. GeoFire selectively loads only the data near certain locations, keeping your applications light and responsive, even with extremely large datasets.

Quickstart

Initalize GeoFire with path to keys in Realtime Database

String pathToReference = "Sites";
Intializing geoFire
Geofire.initialize(pathToReference);

Setting location data

Here setLocation method is used and first is the unique id of the place and other two parameters are latitude and longitude of that place.

bool response = await Geofire.setLocation(
        new DateTime.now().millisecondsSinceEpoch.toString(),
        30.730743,
        76.774948)
        

Retrieving a location

Retrieving a location for a single key in GeoFire happens like below:

Map<String, dynamic> response =
        await Geofire.getLocation("AsH28LWk8MXfwRLfVxgx");

print(response);
        

Geo Queries

GeoFire allows you to query all keys within a geographic area using GeoQuery objects. As the locations for keys change, the query is updated in realtime and fires events letting you know if any relevant keys have moved. GeoQuery parameters can be updated later to change the size and center of the queried area.

response = await Geofire.queryAtLocation(30.730743, 76.774948, 5);

Removing a location

To remove a location and delete it from the database simply pass the location's key to removeLocation:

bool response = await Geofire.removeLocation("AsH28LWk8MXfwRLfVxgx");

print(response);                

Contributing

if you want to contribute to GeoFire, clone the repository and just start making pull requests.

git clone https://github.com/mrdishant/flutter_geofire
This plugin is in development suggestions are welcome. Happy Coding!!!

0.0.1

  • TODO: Describe initial release.

example/README.md

fluter_geofire_example

Demonstrates how to use the fluter_geofire plugin.

Getting Started

For Flutter plugins for other products, see mrdishant@github

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_geofire/flutter_geofire.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 geoFire
Geofire.initialize(pathToReference);

List<String> response;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
  response = await Geofire.queryAtLocation(30.730743, 76.774948, 5);
} 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;

setState(() {
  keysRetrieved = response;
});
  }
  

  @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),
                  ),
                ),
              ),
            ],
          )),
    );
  }

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

print(response);
  }
  
  void setLocationFirst() async {
    bool response =
        await Geofire.setLocation("AsH28LWk8MXfwRLfVxgx", 30.730743, 76.774948);

    print(response);
  }
  
  void removeLocation() async {
    bool response = await Geofire.removeLocation("AsH28LWk8MXfwRLfVxgx");

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

    print(response);
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_geofire: ^0.0.4

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_geofire/flutter_geofire.dart';
  
Version Uploaded Documentation Archive
0.0.4 Nov 30, 2018 Go to the documentation of flutter_geofire 0.0.4 Download flutter_geofire 0.0.4 archive
0.0.3 Nov 30, 2018 Go to the documentation of flutter_geofire 0.0.3 Download flutter_geofire 0.0.3 archive
0.0.2 Nov 28, 2018 Go to the documentation of flutter_geofire 0.0.2 Download flutter_geofire 0.0.2 archive
0.0.1 Nov 28, 2018 Go to the documentation of flutter_geofire 0.0.1 Download flutter_geofire 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
26
Health:
Code health derived from static analysis. [more]
90
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
56
Learn more about scoring.

We analyzed this package on Dec 5, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0
  • pana: 0.12.7
  • Flutter: 1.0.0

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health issues and suggestions

Document public APIs (-10 points)

7 out of 7 API elements (library, class, field or method) have no adequate dartdoc content. Good documentation improves code readability and discoverability through search.

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While there is nothing inherently wrong with versions of 0.0.*, it usually means that the author is still experimenting with the general direction of the API.

The description is too long. (-10 points)

Search engines will display only the first part of the description. Try to keep it under 180 characters.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11
meta 1.1.6
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8