Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Asik-Zaman opened this issue May 22, 2024 · 0 comments
Open

Comments

@Asik-Zaman
Copy link

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);
}
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant