1

I'm using geofence_flutter: ^2.0.0 for geofencing.

Everything working fine, but when I'm trying to stop and start its giving error. My Code

locatoinPunch(){
  await Geofence.startGeofenceService(
    pointedLatitude: locLat,
    pointedLongitude: locLon,
    radiusMeter: locRad,
    eventPeriodInSeconds: 10,
  );

  Geofence.getGeofenceStream().listen((GeofenceEvent event) {
    if (event.toString() == "GeofenceEvent.exit") {
      awesomeDialog(
        title: "Geofence Error",
        message: "Punch from Wrong Location.",
        okBtnString: "Ok",
      );
    } else if (event.toString() == "GeofenceEvent.enter") {
      Geofence.stopGeofenceService();
      locationPunch2();
    }
  });
}

When I'm running locatonPunch() again its giving error

E/flutter (32569): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Bad state: Stream has already been listened to.
E/flutter (32569): #0      _StreamController._subscribe (dart:async/stream_controller.dart:676:7)
E/flutter (32569): #1      _ControllerStream._createSubscription (dart:async/stream_controller.dart:827:19)
E/flutter (32569): #2      _StreamImpl.listen (dart:async/stream_impl.dart:471:9)

On line

Geofence.getGeofenceStream().listen((GeofenceEvent event) {
Honey Last
  • 255
  • 1
  • 3
  • 15

0 Answers0