1

I'm trying to develop a flutter app using geofence_flutter package (I'm using this package because looking to all the other geo-fences package this seems to be the easiest to use). At this moment, my app is able to get the user location and is also able to use de google map API where I locate some custom markers on it. My idea is to get a notification when a user get into some of the areas of those markers, this is the reason about why I'm using the Geofense package.

I tried to implement the package documentation on my code and as a result I get something like this:

List<Geolocation> _geolocation = <Geolocation>[];
_geolocation.add(Geolocation(
                  latitude: list[i]['latitude'],
                  longitude: list[i]['longitude'],
                  radius: llist[i]['radius'].toDouble(),
                  id: list[i]['id'].toString()));

              Geofence.addGeolocation(_geolocation[i], GeolocationEvent.entry)
                  .then((onValue) {

                print("great success");
              }).catchError((onError) {
                print("great failure");
              });
            } 

As you can see, I have a for loop where I add into a list (_geofence) all the information of all the markers that I get from another list. After I added all the markers information (latitude, longitude..) I initialize the notification service:

service = LocalNotificationService();
service.intialize();
service.onNotificationClick.stream.listen(onNoticationListener);


and after that I initialize the geofence service:

Future<void> initPlatformState() async {
    // 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;
    Geofence.initialize();
    Geofence.startListening(GeolocationEvent.entry, (entry) async {
      await service.showNotification(
          id: 0, title: 'Hey', body: 'You are in');
    });

    Geofence.startListening(GeolocationEvent.exit, (entry) async {
      await service.showNotification(
          id: 0, title: 'Hey', body: 'You are out');
    });

    setState(() {});
  }

But even if the user is in the area of a marker, I'm not getting any notification in my device. I know that I'm able to get some notifications because I tested with the code of the package and sometimes (with my proper code) if I put only one marker.... works (1% of times).

anyway, any idea?

I tried to do with other geo-fences services, but they only have examples with one marker and not with multiple markers as I want and in consequences not works.

0 Answers0