Add location permission handling in AttendanceController and improve fetchLogsView method

This commit is contained in:
Vaibhav Surve 2025-05-09 20:56:06 +05:30
parent 82dcf0c8fe
commit 4ce22b149f

View File

@ -49,6 +49,26 @@ class AttendanceController extends GetxController {
log.i("Default date range set: $startDateAttendance to $endDateAttendance");
}
Future<bool> _handleLocationPermission() async {
LocationPermission permission;
permission = await Geolocator.checkPermission();
if (permission == LocationPermission.denied) {
permission = await Geolocator.requestPermission();
if (permission == LocationPermission.denied) {
log.w('Location permissions are denied');
return false;
}
}
if (permission == LocationPermission.deniedForever) {
log.e('Location permissions are permanently denied');
return false;
}
return true;
}
Future<void> fetchProjects() async {
isLoading.value = true;
final response = await ApiService.getProjects();
@ -125,6 +145,12 @@ class AttendanceController extends GetxController {
}
}
final hasLocationPermission = await _handleLocationPermission();
if (!hasLocationPermission) {
uploadingStates[employeeId]?.value = false;
return false;
}
final position = await Geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.high,
);