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,
|
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;
|
||||||
|
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user