Add location permission handling in AttendanceController and improve fetchLogsView method
This commit is contained in:
parent
82dcf0c8fe
commit
4ce22b149f
@ -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,
|
||||
);
|
||||
@ -283,5 +309,5 @@ class AttendanceController extends GetxController {
|
||||
} else {
|
||||
log.e("Failed to fetch attendance log view for ID $id");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user