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");
|
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 {
|
Future<void> fetchProjects() async {
|
||||||
isLoading.value = true;
|
isLoading.value = true;
|
||||||
final response = await ApiService.getProjects();
|
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(
|
final position = await Geolocator.getCurrentPosition(
|
||||||
desiredAccuracy: LocationAccuracy.high,
|
desiredAccuracy: LocationAccuracy.high,
|
||||||
);
|
);
|
||||||
@ -260,28 +286,28 @@ class AttendanceController extends GetxController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> fetchLogsView(String? id) async {
|
Future<void> fetchLogsView(String? id) async {
|
||||||
if (id == null) return;
|
if (id == null) return;
|
||||||
|
|
||||||
isLoading.value = true;
|
isLoading.value = true;
|
||||||
final response = await ApiService.getAttendanceLogView(id);
|
final response = await ApiService.getAttendanceLogView(id);
|
||||||
isLoading.value = false;
|
isLoading.value = false;
|
||||||
|
|
||||||
if (response != null) {
|
if (response != null) {
|
||||||
attendenceLogsView = response
|
attendenceLogsView = response
|
||||||
.map((json) => AttendanceLogViewModel.fromJson(json))
|
.map((json) => AttendanceLogViewModel.fromJson(json))
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
// Sort by activityTime field (latest first)
|
// Sort by activityTime field (latest first)
|
||||||
attendenceLogsView.sort((a, b) {
|
attendenceLogsView.sort((a, b) {
|
||||||
if (a.activityTime == null || b.activityTime == null) return 0; // Handle null values if any
|
if (a.activityTime == null || b.activityTime == null) return 0; // Handle null values if any
|
||||||
return b.activityTime!.compareTo(a.activityTime!); // Sort descending (latest first)
|
return b.activityTime!.compareTo(a.activityTime!); // Sort descending (latest first)
|
||||||
});
|
});
|
||||||
|
|
||||||
log.i("Attendance log view fetched for ID: $id");
|
log.i("Attendance log view fetched for ID: $id");
|
||||||
update();
|
update();
|
||||||
} else {
|
} else {
|
||||||
log.e("Failed to fetch attendance log view for ID $id");
|
log.e("Failed to fetch attendance log view for ID $id");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user