fix(clock_in): improve error handling and state reset logic in clock-in process
This commit is contained in:
@@ -133,6 +133,11 @@ class ClockInBloc extends Bloc<ClockInEvent, ClockInState>
|
||||
CheckInRequested event,
|
||||
Emitter<ClockInState> emit,
|
||||
) 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 GeofenceState geofenceState = _geofenceBloc.state;
|
||||
|
||||
|
||||
@@ -39,7 +39,9 @@ class ClockInPage extends StatelessWidget {
|
||||
child: BlocListener<ClockInBloc, ClockInState>(
|
||||
listenWhen: (ClockInState previous, ClockInState current) =>
|
||||
current.status == ClockInStatus.failure &&
|
||||
current.errorMessage != null,
|
||||
current.errorMessage != null &&
|
||||
(previous.status != current.status ||
|
||||
previous.errorMessage != current.errorMessage),
|
||||
listener: (BuildContext context, ClockInState state) {
|
||||
UiSnackbar.show(
|
||||
context,
|
||||
|
||||
@@ -47,12 +47,21 @@ class _SwipeToCheckInState extends State<SwipeToCheckIn>
|
||||
@override
|
||||
void didUpdateWidget(SwipeToCheckIn oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
// Reset on check-in state change (successful action).
|
||||
if (widget.isCheckedIn != oldWidget.isCheckedIn) {
|
||||
setState(() {
|
||||
_isComplete = false;
|
||||
_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) {
|
||||
|
||||
Reference in New Issue
Block a user