alann-maulana / flutter_beacon

An hybrid iBeacon scanner and transmitter SDK for Flutter Android and iOS.
Apache License 2.0
117 stars 144 forks source link

How to detect when beacon is out of range #39

Closed vmichalak closed 4 years ago

vmichalak commented 4 years ago

Hello, I use flutter_beacon for a connected tag for luggage project. I attempt to push a local notification when the beacon device is out of range but it seems not work.

flutterBeacon.monitoring(regions).listen((result) async {
      //get gps coordinates
      Position position = await Geolocator().getCurrentPosition(desiredAccuracy: LocationAccuracy.best);
      if(position == null){
        position = await Geolocator().getLastKnownPosition(desiredAccuracy: LocationAccuracy.best);
      }

      if(result.monitoringEventType == MonitoringEventType.didEnterRegion) {
        //save to store with timestamp
        Storage().storeValue(
            "beacon_last_latitude", position.latitude.toString());
        Storage().storeValue(
            "beacon_last_longitude", position.longitude.toString());
        Storage().storeValue("beacon_last_timestamp",
            new DateTime.now().millisecondsSinceEpoch.toString());

        prefix0.log("BEACON FOUND: " + position.latitude.toString() + " - " +
            position.longitude.toString());
      } else if(result.monitoringEventType == MonitoringEventType.didExitRegion) {
        LocalNotification(BEACON_NOTIFICATION_CHANNEL, "Out of range", "Warning, your luggage is out of range.").send();
      }
});

In this case, i'm sure the local notification work but is never fired when i go away from my beacon. Do you have any idea to correct this issue ? Perhaps i don't understand the MonitoringEventType.

Thanks in advance, Valentin

alann-maulana commented 4 years ago

Hi @vmichalak

It seems that you already solved your issue, great..

vmichalak commented 4 years ago

Hi @alann-maulana , The problem is between keyboard and chair in this case. I start the monitoring two times and it causes some issues. Sorry.