Skip to content

lead to the "Bad state: Stream has already been listened to" error. #16

@Asik-Zaman

Description

@Asik-Zaman

setLocation(double lat, double long, dynamic radius) async {
latitudeController.text = lat.toString();
longitudeController.text = long.toString();
radiusController.text = radius.toString();

await geofenceStatusSubscription?.cancel();
setState(() {
  isLocation = false;
  isFenceCalled = true;
  todaysAttendanceViewModel.setFenceCall(isFenceCalled);
  print("starting geoFencing Service");

  EasyGeofencing.startGeofenceService(
    pointedLatitude: latitudeController.text,
    pointedLongitude: longitudeController.text,
    radiusMeter: radiusController.text,
    eventPeriodInSeconds: 5,
  );
});

var originalStream = EasyGeofencing.getGeofenceStream();
if (originalStream != null) {
  geofenceStatusSubscription = originalStream.asBroadcastStream().listen((GeofenceStatus status) {
    setState(() {
      geofenceStatus = status.toString();
      if (geofenceStatus == "GeofenceStatus.enter") {
        isInsideOfFence = true;
        todaysAttendanceViewModel.setIsInside(isInsideOfFence);
        isLoginButtonPressed = false;
      } else if (geofenceStatus == "GeofenceStatus.exit") {
        isInsideOfFence = false;
        todaysAttendanceViewModel.setIsInside(isInsideOfFence);
        isLoginButtonPressed = false;
      }
    });
  });
}

}

Future getLatLonData() async {
latLonModel = await AttendanceServices().getLatLon(
userViewModel.userLoginCred.foo,
empInfoListProvider.empModel.companyCode!,
empInfoListProvider.empModel.plantCode!,
);
latLongDetails = latLonModel?.latLongDetails;
var lat, long, radius;
if (latLongDetails != null) {
for (var i = 0; i < latLongDetails!.length; i++) {
lat = latLongDetails![i].latitude;
long = latLongDetails![i].longitude;
radius = latLongDetails![i].radius;
setState(() {
isInsideOfFence = false; // Reset isInsideOfFence
});
await setLocation(lat, long, radius);
}
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions