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 &&
|
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,31 +149,33 @@ 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);
|
||||||
if (scanned && context.mounted) {
|
if (scanned && context.mounted) {
|
||||||
ReadContext(context).read<ClockInBloc>().add(
|
ReadContext(context).read<ClockInBloc>().add(
|
||||||
CheckInRequested(
|
CheckInRequested(
|
||||||
shiftId: selectedShift!.id,
|
shiftId: selectedShift!.id,
|
||||||
notes: geofenceState.overrideNotes,
|
notes: geofenceState.overrideNotes,
|
||||||
isLocationVerified: geofenceState.isLocationVerified,
|
isLocationVerified: geofenceState.isLocationVerified,
|
||||||
isLocationTimedOut: geofenceState.isLocationTimedOut,
|
isLocationTimedOut: geofenceState.isLocationTimedOut,
|
||||||
isGeofenceOverridden: geofenceState.isGeofenceOverridden,
|
isGeofenceOverridden: geofenceState.isGeofenceOverridden,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ReadContext(context).read<ClockInBloc>().add(
|
ReadContext(context).read<ClockInBloc>().add(
|
||||||
CheckInRequested(
|
CheckInRequested(
|
||||||
shiftId: selectedShift!.id,
|
shiftId: selectedShift!.id,
|
||||||
notes: geofenceState.overrideNotes,
|
notes: geofenceState.overrideNotes,
|
||||||
isLocationVerified: geofenceState.isLocationVerified,
|
isLocationVerified: geofenceState.isLocationVerified,
|
||||||
isLocationTimedOut: geofenceState.isLocationTimedOut,
|
isLocationTimedOut: geofenceState.isLocationTimedOut,
|
||||||
isGeofenceOverridden: geofenceState.isGeofenceOverridden,
|
isGeofenceOverridden: geofenceState.isGeofenceOverridden,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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,23 +197,26 @@ 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(
|
||||||
shiftId: state.attendance.activeShiftId!,
|
shiftId: state.attendance.activeShiftId!,
|
||||||
targetLat: geofenceState.targetLat!,
|
targetLat: geofenceState.targetLat!,
|
||||||
targetLng: geofenceState.targetLng!,
|
targetLng: geofenceState.targetLng!,
|
||||||
greetingTitle: geofenceI18n.clock_in_greeting_title,
|
greetingTitle: geofenceI18n.clock_in_greeting_title,
|
||||||
greetingBody: geofenceI18n.clock_in_greeting_body,
|
greetingBody: geofenceI18n.clock_in_greeting_body,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user