diff --git a/android/app/src/main/res/drawable-anydpi-v21/ic_bg_service_small.xml b/android/app/src/main/res/drawable-anydpi-v21/ic_bg_service_small.xml new file mode 100644 index 00000000..84acaecb --- /dev/null +++ b/android/app/src/main/res/drawable-anydpi-v21/ic_bg_service_small.xml @@ -0,0 +1,4 @@ + + \ No newline at end of file diff --git a/lib/screens/attendance/attendance_screen.dart b/lib/screens/attendance/attendance_screen.dart index 95d28cd5..85246fc1 100644 --- a/lib/screens/attendance/attendance_screen.dart +++ b/lib/screens/attendance/attendance_screen.dart @@ -360,17 +360,13 @@ class _CheckInTabState extends ConsumerState<_CheckInTab> { final schedulesAsync = ref.watch(dutySchedulesProvider); final logsAsync = ref.watch(attendanceLogsProvider); final allowTracking = profile?.allowTracking ?? false; - // local state for optimistic switch update and to avoid flicker while the - // profile stream lags. Once the network request completes we keep the - // local value until the provider returns the same value. - bool effectiveTracking; - if (_trackingSaving) { - effectiveTracking = _trackingLocal; - } else if (_trackingLocal != allowTracking) { - effectiveTracking = _trackingLocal; - } else { - effectiveTracking = allowTracking; - } + // local state for optimistic switch update. We only trust `_trackingLocal` + // while a save is in flight – after that the server-side value (`allowTracking`) + // is authoritative. This ensures the toggle correctly reflects the persisted + // setting when the app restarts. + final bool effectiveTracking = _trackingSaving + ? _trackingLocal + : allowTracking; if (profile == null) { return const Center(child: CircularProgressIndicator()); @@ -938,6 +934,11 @@ class _CheckInTabState extends ConsumerState<_CheckInTab> { lat: position.latitude, lng: position.longitude, ); + // automatically enable tracking when user checks in + try { + await ref.read(whereaboutsControllerProvider).setTracking(true); + } catch (_) {} + _trackingLocal = true; // reflect new state immediately // Update live position immediately on check-in ref.read(whereaboutsControllerProvider).updatePositionNow(); if (mounted) { @@ -1017,6 +1018,11 @@ class _CheckInTabState extends ConsumerState<_CheckInTab> { lng: position.longitude, justification: checkOutJustification, ); + // automatically disable tracking when user checks out + try { + await ref.read(whereaboutsControllerProvider).setTracking(false); + } catch (_) {} + _trackingLocal = false; // Update live position immediately on check-out ref.read(whereaboutsControllerProvider).updatePositionNow(); if (mounted) {