refactor: Improve code readability by formatting and restructuring Bloc context usage in ClockInActionSection

This commit is contained in:
Achintha Isuru
2026-03-13 20:44:45 -04:00
parent 1bbd306ca0
commit c92138a573

View File

@@ -73,9 +73,9 @@ class ClockInActionSection extends StatelessWidget {
previous.attendance.isCheckedIn && previous.attendance.isCheckedIn &&
!current.attendance.isCheckedIn, !current.attendance.isCheckedIn,
listener: (BuildContext context, ClockInState _) { listener: (BuildContext context, ClockInState _) {
ReadContext(context) ReadContext(
.read<GeofenceBloc>() context,
.add(const BackgroundTrackingStopped()); ).read<GeofenceBloc>().add(const BackgroundTrackingStopped());
}, },
), ),
], ],
@@ -116,12 +116,12 @@ class ClockInActionSection extends StatelessWidget {
return BlocBuilder<GeofenceBloc, GeofenceState>( return BlocBuilder<GeofenceBloc, GeofenceState>(
builder: (BuildContext context, GeofenceState geofenceState) { builder: (BuildContext context, GeofenceState geofenceState) {
final bool hasCoordinates = selectedShift?.latitude != null && final bool hasCoordinates =
selectedShift?.longitude != null; selectedShift?.latitude != null && selectedShift?.longitude != null;
// Geofence only gates clock-in, never clock-out. When already // Geofence only gates clock-in, never clock-out. When already
// checked in the swipe must always be enabled for checkout. // checked in the swipe must always be enabled for checkout.
final bool isGeofenceBlocking = !isCheckedIn && final bool isGeofenceBlocking =
hasCoordinates && hasCoordinates &&
!geofenceState.isLocationVerified && !geofenceState.isLocationVerified &&
!geofenceState.isLocationTimedOut && !geofenceState.isLocationTimedOut &&
@@ -149,7 +149,9 @@ class ClockInActionSection extends StatelessWidget {
/// Triggers the check-in flow, reading geofence state for location data. /// Triggers the check-in flow, reading geofence state for location data.
Future<void> _handleCheckIn(BuildContext context) async { Future<void> _handleCheckIn(BuildContext context) async {
final GeofenceState geofenceState = ReadContext(context).read<GeofenceBloc>().state; final GeofenceState geofenceState = ReadContext(
context,
).read<GeofenceBloc>().state;
if (checkInMode == 'nfc') { if (checkInMode == 'nfc') {
final bool scanned = await showNfcScanDialog(context); final bool scanned = await showNfcScanDialog(context);
@@ -184,7 +186,9 @@ class ClockInActionSection extends StatelessWidget {
builder: (BuildContext dialogContext) => LunchBreakDialog( builder: (BuildContext dialogContext) => LunchBreakDialog(
onComplete: () { onComplete: () {
Modular.to.popSafe(); Modular.to.popSafe();
ReadContext(context).read<ClockInBloc>().add(const CheckOutRequested()); ReadContext(
context,
).read<ClockInBloc>().add(const CheckOutRequested());
}, },
), ),
); );
@@ -193,13 +197,16 @@ class ClockInActionSection extends StatelessWidget {
/// Dispatches [BackgroundTrackingStarted] if the geofence has target /// Dispatches [BackgroundTrackingStarted] if the geofence has target
/// coordinates after a successful check-in. /// coordinates after a successful check-in.
void _startBackgroundTracking(BuildContext context, ClockInState state) { void _startBackgroundTracking(BuildContext context, ClockInState state) {
final GeofenceState geofenceState = ReadContext(context).read<GeofenceBloc>().state; final GeofenceState geofenceState = ReadContext(
context,
).read<GeofenceBloc>().state;
if (geofenceState.targetLat != null && if (geofenceState.targetLat != null &&
geofenceState.targetLng != null && geofenceState.targetLng != null &&
state.attendance.activeShiftId != null) { state.attendance.activeShiftId != null) {
final TranslationsStaffClockInGeofenceEn geofenceI18n = final TranslationsStaffClockInGeofenceEn geofenceI18n = Translations.of(
Translations.of(context).staff.clock_in.geofence; context,
).staff.clock_in.geofence;
ReadContext(context).read<GeofenceBloc>().add( ReadContext(context).read<GeofenceBloc>().add(
BackgroundTrackingStarted( BackgroundTrackingStarted(