Refactor clock-in feature: Introduce validation pipeline and interaction strategies

- Added a validation pipeline for clock-in actions, including geofence, time window, and override notes validators.
- Created a context class for passing validation data and results.
- Implemented check-in interaction strategies for swipe and NFC methods, encapsulating their UI and behavior.
- Removed redundant utility functions and centralized time formatting in a new utility file.
- Enhanced the notification service to handle clock-in and clock-out notifications separately.
- Updated the ClockInBloc to utilize the new validation and notification services.
- Cleaned up the ClockInActionSection widget to use the new interaction strategies and removed unnecessary listeners.
This commit is contained in:
Achintha Isuru
2026-03-14 19:58:43 -04:00
parent e3f7e1ac3e
commit 28a219bbea
29 changed files with 864 additions and 394 deletions

View File

@@ -6,6 +6,7 @@ export 'src/domain/arguments/usecase_argument.dart';
export 'src/domain/usecases/usecase.dart';
export 'src/utils/date_time_utils.dart';
export 'src/utils/geo_utils.dart';
export 'src/utils/time_utils.dart';
export 'src/presentation/widgets/web_mobile_frame.dart';
export 'src/presentation/mixins/bloc_error_handler.dart';
export 'src/presentation/observers/core_bloc_observer.dart';

View File

@@ -0,0 +1,30 @@
import 'package:intl/intl.dart';
/// Formats a time string (ISO 8601 or HH:mm) into 12-hour format
/// (e.g. "9:00 AM").
///
/// Returns the original string unchanged if parsing fails.
String formatTime(String timeStr) {
if (timeStr.isEmpty) return '';
try {
final DateTime dt = DateTime.parse(timeStr);
return DateFormat('h:mm a').format(dt);
} catch (_) {
try {
final List<String> parts = timeStr.split(':');
if (parts.length >= 2) {
final DateTime dt = DateTime(
2022,
1,
1,
int.parse(parts[0]),
int.parse(parts[1]),
);
return DateFormat('h:mm a').format(dt);
}
return timeStr;
} catch (_) {
return timeStr;
}
}
}

View File

@@ -18,6 +18,7 @@ dependencies:
design_system:
path: ../design_system
intl: ^0.20.0
flutter_bloc: ^8.1.0
equatable: ^2.0.8
flutter_modular: ^6.4.1