-
Notifications
You must be signed in to change notification settings - Fork 21
Description
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);
}
}
}