fix(clock_in): improve error handling and state reset logic in clock-in process

This commit is contained in:
Achintha Isuru
2026-03-14 20:11:19 -04:00
parent aa556c4a05
commit e93f7f7004
3 changed files with 17 additions and 1 deletions

View File

@@ -133,6 +133,11 @@ class ClockInBloc extends Bloc<ClockInEvent, ClockInState>
CheckInRequested event, CheckInRequested event,
Emitter<ClockInState> emit, Emitter<ClockInState> emit,
) async { ) async {
// Clear previous error so repeated failures are always emitted as new states.
if (state.errorMessage != null) {
emit(state.copyWith(errorMessage: null));
}
final Shift? shift = state.selectedShift; final Shift? shift = state.selectedShift;
final GeofenceState geofenceState = _geofenceBloc.state; final GeofenceState geofenceState = _geofenceBloc.state;

View File

@@ -39,7 +39,9 @@ class ClockInPage extends StatelessWidget {
child: BlocListener<ClockInBloc, ClockInState>( child: BlocListener<ClockInBloc, ClockInState>(
listenWhen: (ClockInState previous, ClockInState current) => listenWhen: (ClockInState previous, ClockInState current) =>
current.status == ClockInStatus.failure && current.status == ClockInStatus.failure &&
current.errorMessage != null, current.errorMessage != null &&
(previous.status != current.status ||
previous.errorMessage != current.errorMessage),
listener: (BuildContext context, ClockInState state) { listener: (BuildContext context, ClockInState state) {
UiSnackbar.show( UiSnackbar.show(
context, context,

View File

@@ -47,12 +47,21 @@ class _SwipeToCheckInState extends State<SwipeToCheckIn>
@override @override
void didUpdateWidget(SwipeToCheckIn oldWidget) { void didUpdateWidget(SwipeToCheckIn oldWidget) {
super.didUpdateWidget(oldWidget); super.didUpdateWidget(oldWidget);
// Reset on check-in state change (successful action).
if (widget.isCheckedIn != oldWidget.isCheckedIn) { if (widget.isCheckedIn != oldWidget.isCheckedIn) {
setState(() { setState(() {
_isComplete = false; _isComplete = false;
_dragValue = 0.0; _dragValue = 0.0;
}); });
} }
// Reset on error: loading finished but check-in state didn't change.
if (oldWidget.isLoading && !widget.isLoading &&
widget.isCheckedIn == oldWidget.isCheckedIn && _isComplete) {
setState(() {
_isComplete = false;
_dragValue = 0.0;
});
}
} }
void _onDragUpdate(DragUpdateDetails details, double maxWidth) { void _onDragUpdate(DragUpdateDetails details, double maxWidth) {