From c92138a5738201bd4369b961dea8850574aff4a8 Mon Sep 17 00:00:00 2001 From: Achintha Isuru Date: Fri, 13 Mar 2026 20:44:45 -0400 Subject: [PATCH] refactor: Improve code readability by formatting and restructuring Bloc context usage in ClockInActionSection --- .../widgets/clock_in_action_section.dart | 77 ++++++++++--------- 1 file changed, 42 insertions(+), 35 deletions(-) diff --git a/apps/mobile/packages/features/staff/clock_in/lib/src/presentation/widgets/clock_in_action_section.dart b/apps/mobile/packages/features/staff/clock_in/lib/src/presentation/widgets/clock_in_action_section.dart index 279f6357..2a03d44c 100644 --- a/apps/mobile/packages/features/staff/clock_in/lib/src/presentation/widgets/clock_in_action_section.dart +++ b/apps/mobile/packages/features/staff/clock_in/lib/src/presentation/widgets/clock_in_action_section.dart @@ -73,9 +73,9 @@ class ClockInActionSection extends StatelessWidget { previous.attendance.isCheckedIn && !current.attendance.isCheckedIn, listener: (BuildContext context, ClockInState _) { - ReadContext(context) - .read() - .add(const BackgroundTrackingStopped()); + ReadContext( + context, + ).read().add(const BackgroundTrackingStopped()); }, ), ], @@ -116,12 +116,12 @@ class ClockInActionSection extends StatelessWidget { return BlocBuilder( builder: (BuildContext context, GeofenceState geofenceState) { - final bool hasCoordinates = selectedShift?.latitude != null && - selectedShift?.longitude != null; + final bool hasCoordinates = + selectedShift?.latitude != null && selectedShift?.longitude != null; // Geofence only gates clock-in, never clock-out. When already // checked in the swipe must always be enabled for checkout. - final bool isGeofenceBlocking = !isCheckedIn && + final bool isGeofenceBlocking = hasCoordinates && !geofenceState.isLocationVerified && !geofenceState.isLocationTimedOut && @@ -149,31 +149,33 @@ class ClockInActionSection extends StatelessWidget { /// Triggers the check-in flow, reading geofence state for location data. Future _handleCheckIn(BuildContext context) async { - final GeofenceState geofenceState = ReadContext(context).read().state; + final GeofenceState geofenceState = ReadContext( + context, + ).read().state; if (checkInMode == 'nfc') { final bool scanned = await showNfcScanDialog(context); if (scanned && context.mounted) { ReadContext(context).read().add( - CheckInRequested( - shiftId: selectedShift!.id, - notes: geofenceState.overrideNotes, - isLocationVerified: geofenceState.isLocationVerified, - isLocationTimedOut: geofenceState.isLocationTimedOut, - isGeofenceOverridden: geofenceState.isGeofenceOverridden, - ), - ); + CheckInRequested( + shiftId: selectedShift!.id, + notes: geofenceState.overrideNotes, + isLocationVerified: geofenceState.isLocationVerified, + isLocationTimedOut: geofenceState.isLocationTimedOut, + isGeofenceOverridden: geofenceState.isGeofenceOverridden, + ), + ); } } else { ReadContext(context).read().add( - CheckInRequested( - shiftId: selectedShift!.id, - notes: geofenceState.overrideNotes, - isLocationVerified: geofenceState.isLocationVerified, - isLocationTimedOut: geofenceState.isLocationTimedOut, - isGeofenceOverridden: geofenceState.isGeofenceOverridden, - ), - ); + CheckInRequested( + shiftId: selectedShift!.id, + notes: geofenceState.overrideNotes, + isLocationVerified: geofenceState.isLocationVerified, + isLocationTimedOut: geofenceState.isLocationTimedOut, + isGeofenceOverridden: geofenceState.isGeofenceOverridden, + ), + ); } } @@ -184,7 +186,9 @@ class ClockInActionSection extends StatelessWidget { builder: (BuildContext dialogContext) => LunchBreakDialog( onComplete: () { Modular.to.popSafe(); - ReadContext(context).read().add(const CheckOutRequested()); + ReadContext( + context, + ).read().add(const CheckOutRequested()); }, ), ); @@ -193,23 +197,26 @@ class ClockInActionSection extends StatelessWidget { /// Dispatches [BackgroundTrackingStarted] if the geofence has target /// coordinates after a successful check-in. void _startBackgroundTracking(BuildContext context, ClockInState state) { - final GeofenceState geofenceState = ReadContext(context).read().state; + final GeofenceState geofenceState = ReadContext( + context, + ).read().state; if (geofenceState.targetLat != null && geofenceState.targetLng != null && state.attendance.activeShiftId != null) { - final TranslationsStaffClockInGeofenceEn geofenceI18n = - Translations.of(context).staff.clock_in.geofence; + final TranslationsStaffClockInGeofenceEn geofenceI18n = Translations.of( + context, + ).staff.clock_in.geofence; ReadContext(context).read().add( - BackgroundTrackingStarted( - shiftId: state.attendance.activeShiftId!, - targetLat: geofenceState.targetLat!, - targetLng: geofenceState.targetLng!, - greetingTitle: geofenceI18n.clock_in_greeting_title, - greetingBody: geofenceI18n.clock_in_greeting_body, - ), - ); + BackgroundTrackingStarted( + shiftId: state.attendance.activeShiftId!, + targetLat: geofenceState.targetLat!, + targetLng: geofenceState.targetLng!, + greetingTitle: geofenceI18n.clock_in_greeting_title, + greetingBody: geofenceI18n.clock_in_greeting_body, + ), + ); } } }