refactor: Improve code readability by formatting and restructuring Bloc context usage in ClockInActionSection
This commit is contained in:
@@ -73,9 +73,9 @@ class ClockInActionSection extends StatelessWidget {
|
||||
previous.attendance.isCheckedIn &&
|
||||
!current.attendance.isCheckedIn,
|
||||
listener: (BuildContext context, ClockInState _) {
|
||||
ReadContext(context)
|
||||
.read<GeofenceBloc>()
|
||||
.add(const BackgroundTrackingStopped());
|
||||
ReadContext(
|
||||
context,
|
||||
).read<GeofenceBloc>().add(const BackgroundTrackingStopped());
|
||||
},
|
||||
),
|
||||
],
|
||||
@@ -116,12 +116,12 @@ class ClockInActionSection extends StatelessWidget {
|
||||
|
||||
return BlocBuilder<GeofenceBloc, GeofenceState>(
|
||||
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<void> _handleCheckIn(BuildContext context) async {
|
||||
final GeofenceState geofenceState = ReadContext(context).read<GeofenceBloc>().state;
|
||||
final GeofenceState geofenceState = ReadContext(
|
||||
context,
|
||||
).read<GeofenceBloc>().state;
|
||||
|
||||
if (checkInMode == 'nfc') {
|
||||
final bool scanned = await showNfcScanDialog(context);
|
||||
if (scanned && context.mounted) {
|
||||
ReadContext(context).read<ClockInBloc>().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<ClockInBloc>().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<ClockInBloc>().add(const CheckOutRequested());
|
||||
ReadContext(
|
||||
context,
|
||||
).read<ClockInBloc>().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<GeofenceBloc>().state;
|
||||
final GeofenceState geofenceState = ReadContext(
|
||||
context,
|
||||
).read<GeofenceBloc>().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<GeofenceBloc>().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,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user