Add explicit types and improve type safety across codebase
This commit adds explicit type annotations to variables, function parameters, and return types throughout the codebase, particularly in widget trees, Bloc logic, and repository implementations. The changes improve code readability, maintainability, and type safety, and align with Dart best practices. No business logic was changed.
This commit is contained in:
@@ -21,15 +21,15 @@ class ViewOrdersRepositoryImpl implements IViewOrdersRepository {
|
||||
required DateTime start,
|
||||
required DateTime end,
|
||||
}) async {
|
||||
final businessId = dc.ClientSessionStore.instance.session?.business?.id;
|
||||
final String? businessId = dc.ClientSessionStore.instance.session?.business?.id;
|
||||
if (businessId == null || businessId.isEmpty) {
|
||||
await _firebaseAuth.signOut();
|
||||
throw Exception('Business is missing. Please sign in again.');
|
||||
}
|
||||
|
||||
final startTimestamp = _toTimestamp(_startOfDay(start));
|
||||
final endTimestamp = _toTimestamp(_endOfDay(end));
|
||||
final result = await _dataConnect
|
||||
final fdc.Timestamp startTimestamp = _toTimestamp(_startOfDay(start));
|
||||
final fdc.Timestamp endTimestamp = _toTimestamp(_endOfDay(end));
|
||||
final fdc.QueryResult<dc.ListShiftRolesByBusinessAndDateRangeData, dc.ListShiftRolesByBusinessAndDateRangeVariables> result = await _dataConnect
|
||||
.listShiftRolesByBusinessAndDateRange(
|
||||
businessId: businessId,
|
||||
start: startTimestamp,
|
||||
@@ -37,28 +37,28 @@ class ViewOrdersRepositoryImpl implements IViewOrdersRepository {
|
||||
)
|
||||
.execute();
|
||||
|
||||
final businessName =
|
||||
final String businessName =
|
||||
dc.ClientSessionStore.instance.session?.business?.businessName ??
|
||||
'Your Company';
|
||||
|
||||
return result.data.shiftRoles.map((shiftRole) {
|
||||
return result.data.shiftRoles.map((dc.ListShiftRolesByBusinessAndDateRangeShiftRoles shiftRole) {
|
||||
print(
|
||||
'ViewOrders shiftRole: shiftId=${shiftRole.shiftId} roleId=${shiftRole.roleId} '
|
||||
'startTime=${shiftRole.startTime?.toJson()} endTime=${shiftRole.endTime?.toJson()} '
|
||||
'hours=${shiftRole.hours} totalValue=${shiftRole.totalValue}',
|
||||
);
|
||||
final shiftDate = shiftRole.shift.date?.toDateTime();
|
||||
final dateStr = shiftDate == null
|
||||
final DateTime? shiftDate = shiftRole.shift.date?.toDateTime();
|
||||
final String dateStr = shiftDate == null
|
||||
? ''
|
||||
: DateFormat('yyyy-MM-dd').format(shiftDate);
|
||||
final startTime = _formatTime(shiftRole.startTime);
|
||||
final endTime = _formatTime(shiftRole.endTime);
|
||||
final filled = shiftRole.assigned ?? 0;
|
||||
final workersNeeded = shiftRole.count;
|
||||
final hours = shiftRole.hours ?? 0;
|
||||
final totalValue = shiftRole.totalValue ?? 0;
|
||||
final hourlyRate = _hourlyRate(shiftRole.totalValue, shiftRole.hours);
|
||||
final status = filled >= workersNeeded ? 'filled' : 'open';
|
||||
final String startTime = _formatTime(shiftRole.startTime);
|
||||
final String endTime = _formatTime(shiftRole.endTime);
|
||||
final int filled = shiftRole.assigned ?? 0;
|
||||
final int workersNeeded = shiftRole.count;
|
||||
final double hours = shiftRole.hours ?? 0;
|
||||
final double totalValue = shiftRole.totalValue ?? 0;
|
||||
final double hourlyRate = _hourlyRate(shiftRole.totalValue, shiftRole.hours);
|
||||
final String status = filled >= workersNeeded ? 'filled' : 'open';
|
||||
|
||||
return domain.OrderItem(
|
||||
id: _shiftRoleKey(shiftRole.shiftId, shiftRole.roleId),
|
||||
@@ -84,15 +84,15 @@ class ViewOrdersRepositoryImpl implements IViewOrdersRepository {
|
||||
Future<Map<String, List<Map<String, dynamic>>>> getAcceptedApplicationsForDay(
|
||||
DateTime day,
|
||||
) async {
|
||||
final businessId = dc.ClientSessionStore.instance.session?.business?.id;
|
||||
final String? businessId = dc.ClientSessionStore.instance.session?.business?.id;
|
||||
if (businessId == null || businessId.isEmpty) {
|
||||
await _firebaseAuth.signOut();
|
||||
throw Exception('Business is missing. Please sign in again.');
|
||||
}
|
||||
|
||||
final dayStart = _toTimestamp(_startOfDay(day));
|
||||
final dayEnd = _toTimestamp(_endOfDay(day));
|
||||
final result = await _dataConnect
|
||||
final fdc.Timestamp dayStart = _toTimestamp(_startOfDay(day));
|
||||
final fdc.Timestamp dayEnd = _toTimestamp(_endOfDay(day));
|
||||
final fdc.QueryResult<dc.ListAcceptedApplicationsByBusinessForDayData, dc.ListAcceptedApplicationsByBusinessForDayVariables> result = await _dataConnect
|
||||
.listAcceptedApplicationsByBusinessForDay(
|
||||
businessId: businessId,
|
||||
dayStart: dayStart,
|
||||
@@ -100,13 +100,13 @@ class ViewOrdersRepositoryImpl implements IViewOrdersRepository {
|
||||
)
|
||||
.execute();
|
||||
|
||||
final Map<String, List<Map<String, dynamic>>> grouped = {};
|
||||
for (final application in result.data.applications) {
|
||||
final Map<String, List<Map<String, dynamic>>> grouped = <String, List<Map<String, dynamic>>>{};
|
||||
for (final dc.ListAcceptedApplicationsByBusinessForDayApplications application in result.data.applications) {
|
||||
print(
|
||||
'ViewOrders app: shiftId=${application.shiftId} roleId=${application.roleId} '
|
||||
'checkIn=${application.checkInTime?.toJson()} checkOut=${application.checkOutTime?.toJson()}',
|
||||
);
|
||||
final key = _shiftRoleKey(application.shiftId, application.roleId);
|
||||
final String key = _shiftRoleKey(application.shiftId, application.roleId);
|
||||
grouped.putIfAbsent(key, () => <Map<String, dynamic>>[]);
|
||||
grouped[key]!.add(<String, dynamic>{
|
||||
'id': application.id,
|
||||
@@ -124,9 +124,9 @@ class ViewOrdersRepositoryImpl implements IViewOrdersRepository {
|
||||
}
|
||||
|
||||
fdc.Timestamp _toTimestamp(DateTime dateTime) {
|
||||
final utc = dateTime.toUtc();
|
||||
final seconds = utc.millisecondsSinceEpoch ~/ 1000;
|
||||
final nanoseconds = (utc.microsecondsSinceEpoch % 1000000) * 1000;
|
||||
final DateTime utc = dateTime.toUtc();
|
||||
final int seconds = utc.millisecondsSinceEpoch ~/ 1000;
|
||||
final int nanoseconds = (utc.microsecondsSinceEpoch % 1000000) * 1000;
|
||||
return fdc.Timestamp(nanoseconds, seconds);
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ class ViewOrdersRepositoryImpl implements IViewOrdersRepository {
|
||||
if (timestamp == null) {
|
||||
return '';
|
||||
}
|
||||
final dateTime = timestamp.toDateTime();
|
||||
final DateTime dateTime = timestamp.toDateTime();
|
||||
return DateFormat('HH:mm').format(dateTime);
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ class ViewOrdersCubit extends Cubit<ViewOrdersState> {
|
||||
final List<OrderItem> orders = await _getOrdersUseCase(
|
||||
OrdersRangeArguments(start: rangeStart, end: rangeEnd),
|
||||
);
|
||||
final apps = await _getAcceptedAppsUseCase(
|
||||
final Map<String, List<Map<String, dynamic>>> apps = await _getAcceptedAppsUseCase(
|
||||
OrdersDayArguments(day: dayForApps),
|
||||
);
|
||||
final List<OrderItem> updatedOrders = _applyApplications(orders, apps);
|
||||
@@ -70,7 +70,7 @@ class ViewOrdersCubit extends Cubit<ViewOrdersState> {
|
||||
final DateTime? selectedDate = state.selectedDate;
|
||||
final DateTime updatedSelectedDate =
|
||||
selectedDate != null &&
|
||||
calendarDays.any((day) => _isSameDay(day, selectedDate))
|
||||
calendarDays.any((DateTime day) => _isSameDay(day, selectedDate))
|
||||
? selectedDate
|
||||
: calendarDays.first;
|
||||
emit(
|
||||
@@ -106,7 +106,7 @@ class ViewOrdersCubit extends Cubit<ViewOrdersState> {
|
||||
|
||||
Future<void> _refreshAcceptedApplications(DateTime day) async {
|
||||
try {
|
||||
final apps = await _getAcceptedAppsUseCase(
|
||||
final Map<String, List<Map<String, dynamic>>> apps = await _getAcceptedAppsUseCase(
|
||||
OrdersDayArguments(day: day),
|
||||
);
|
||||
final List<OrderItem> updatedOrders =
|
||||
@@ -122,14 +122,14 @@ class ViewOrdersCubit extends Cubit<ViewOrdersState> {
|
||||
List<OrderItem> orders,
|
||||
Map<String, List<Map<String, dynamic>>> apps,
|
||||
) {
|
||||
return orders.map((order) {
|
||||
final confirmed = apps[order.id] ?? const <Map<String, dynamic>>[];
|
||||
return orders.map((OrderItem order) {
|
||||
final List<Map<String, dynamic>> confirmed = apps[order.id] ?? const <Map<String, dynamic>>[];
|
||||
if (confirmed.isEmpty) {
|
||||
return order;
|
||||
}
|
||||
|
||||
final filled = confirmed.length;
|
||||
final status =
|
||||
final int filled = confirmed.length;
|
||||
final String status =
|
||||
filled >= order.workersNeeded ? 'filled' : order.status;
|
||||
return OrderItem(
|
||||
id: order.id,
|
||||
|
||||
Reference in New Issue
Block a user