refactor: simplify widget structure and improve date selection logic in clock-in features

This commit is contained in:
Achintha Isuru
2026-03-13 12:14:06 -04:00
parent ec880007d0
commit 2c1c71ad01
4 changed files with 107 additions and 131 deletions

View File

@@ -4,7 +4,6 @@ import 'package:krow_domain/krow_domain.dart';
import '../bloc/clock_in_bloc.dart';
import '../bloc/clock_in_event.dart';
import '../bloc/clock_in_state.dart';
import 'clock_in_helpers.dart';
import 'early_check_in_banner.dart';
import 'lunch_break_modal.dart';

View File

@@ -16,7 +16,7 @@ class DateSelector extends StatelessWidget {
@override
Widget build(BuildContext context) {
final DateTime today = DateTime.now();
final List<DateTime> dates = List.generate(7, (int index) {
final List<DateTime> dates = List<DateTime>.generate(7, (int index) {
return today.add(Duration(days: index - 3));
});
@@ -31,7 +31,7 @@ class DateSelector extends StatelessWidget {
return Expanded(
child: GestureDetector(
onTap: () => onSelect(date),
onTap: isToday ? () => onSelect(date) : null,
child: AnimatedContainer(
duration: const Duration(milliseconds: 200),
margin: const EdgeInsets.symmetric(
@@ -40,58 +40,55 @@ class DateSelector extends StatelessWidget {
decoration: BoxDecoration(
color: isSelected ? UiColors.primary : UiColors.white,
borderRadius: UiConstants.radiusLg,
boxShadow: isSelected
? <BoxShadow>[
BoxShadow(
color: UiColors.primary.withValues(alpha: 0.3),
blurRadius: 10,
offset: const Offset(0, 4),
),
]
: <BoxShadow>[],
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
DateFormat('d').format(date),
style: UiTypography.title1m.copyWith(
fontWeight: FontWeight.bold,
color:
isSelected ? UiColors.white : UiColors.foreground,
),
),
const SizedBox(height: 2),
Text(
DateFormat('E').format(date),
style: UiTypography.footnote2r.copyWith(
color: isSelected
? UiColors.white.withValues(alpha: 0.8)
: UiColors.textInactive,
),
),
const SizedBox(height: UiConstants.space1),
if (hasShift)
Container(
width: 6,
height: 6,
decoration: BoxDecoration(
color: isSelected ? UiColors.white : UiColors.primary,
shape: BoxShape.circle,
child: Opacity(
opacity: isToday ? 1.0 : 0.4,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
DateFormat('d').format(date),
style: UiTypography.title1m.copyWith(
fontWeight: FontWeight.bold,
color: isSelected
? UiColors.white
: UiColors.foreground,
),
)
else if (isToday && !isSelected)
Container(
width: 6,
height: 6,
decoration: const BoxDecoration(
color: UiColors.border,
shape: BoxShape.circle,
),
const SizedBox(height: 2),
Text(
DateFormat('E').format(date),
style: UiTypography.footnote2r.copyWith(
color: isSelected
? UiColors.white.withValues(alpha: 0.8)
: UiColors.textInactive,
),
)
else
const SizedBox(height: 6),
],
),
const SizedBox(height: UiConstants.space1),
if (hasShift)
Container(
width: 6,
height: 6,
decoration: BoxDecoration(
color: isSelected
? UiColors.white
: UiColors.primary,
shape: BoxShape.circle,
),
)
else if (isToday && !isSelected)
Container(
width: 6,
height: 6,
decoration: const BoxDecoration(
color: UiColors.border,
shape: BoxShape.circle,
),
)
else
const SizedBox(height: UiConstants.space3),
],
),
),
),
),
@@ -100,11 +97,13 @@ class DateSelector extends StatelessWidget {
),
);
}
/// Helper to check if two dates are on the same calendar day (ignoring time).
bool _isSameDay(DateTime a, DateTime b) {
return a.year == b.year && a.month == b.month && a.day == b.day;
}
/// Formats a [DateTime] as an ISO date string (yyyy-MM-dd) for comparison with shift dates.
String _formatDateIso(DateTime date) {
return DateFormat('yyyy-MM-dd').format(date);
}