fluttercommunity / firestore_helpers

Firestore Helpers - Firestore helper function to create dynamic and location based queries. Maintainer: @escamoteur
https://pub.dev/packages/firestore_helpers
MIT License
48 stars 19 forks source link

Please help -- it is not working #4

Closed tegab closed 6 years ago

tegab commented 6 years ago

I can not seem to get it to work... please help me

class Test extends State<TestGeoHelpers> {
  double _lat = 51.0769547;
  double _lng = -113.9421552;

  String _geo = '';

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('Test'),
      ),
      body: new Container(
        alignment: Alignment.center,
        padding: EdgeInsets.all(16.0),
        child: new Column(
          children: <Widget>[
            new RaisedButton(
              child: new Text('GEO'),
              onPressed: () {
                Area area =
                    new Area(new GeoPoint(51.0769547, -113.9421552), 0.7);
                getEvents(area);
              },
            ),
            new Text(_geo),
          ],
        ),
      ),
    );
  }

  Stream<List<EventData>> getEvents(area) {
    GeoPoint areagp = new GeoPoint(_lat, _lng);
    Area searchArea = new Area(areagp, 4.0);

    //try {
    return getDataInArea(
      source: Firestore.instance.collection('jobs'),
      area: searchArea,
      locationFieldNameInDB: 'geopoint',
      mapper: (eventDoc) {
        print(eventDoc.data['title'].toString());
      },
    );
  }
}

class Event {
  String title;
  GeoPoint geopoint;
}

class EventData {
  Event event;
  double distance;

  EventData(this.event, [this.distance]);
}
escamoteur commented 6 years ago

Sorry but your edscription is a bit vague, what happens excatly? How does your database looks like?