Fix: Resolve critical linting issues and bugs (concurrency, syntax, dead code)

This commit is contained in:
2026-02-10 19:12:01 +05:30
parent 5e7bf0d5c0
commit 7570ffa3b9
46 changed files with 4057 additions and 1299 deletions

View File

@@ -1,5 +1,6 @@
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:krow_core/core.dart';
import 'package:krow_domain/krow_domain.dart';
import 'package:staff_home/src/domain/usecases/get_home_shifts.dart';
@@ -8,7 +9,7 @@ import 'package:staff_home/src/domain/repositories/home_repository.dart';
part 'home_state.dart';
/// Simple Cubit to manage home page state (shifts + loading/error).
class HomeCubit extends Cubit<HomeState> {
class HomeCubit extends Cubit<HomeState> with BlocErrorHandler<HomeState> {
final GetHomeShifts _getHomeShifts;
final HomeRepository _repository;
@@ -20,29 +21,32 @@ class HomeCubit extends Cubit<HomeState> {
Future<void> loadShifts() async {
if (isClosed) return;
emit(state.copyWith(status: HomeStatus.loading));
try {
final result = await _getHomeShifts.call();
final name = await _repository.getStaffName();
if (isClosed) return;
emit(
state.copyWith(
status: HomeStatus.loaded,
todayShifts: result.today,
tomorrowShifts: result.tomorrow,
recommendedShifts: result.recommended,
staffName: name,
// Mock profile status for now, ideally fetched from a user repository
isProfileComplete: false,
),
);
} catch (e) {
if (isClosed) return;
emit(
state.copyWith(status: HomeStatus.error, errorMessage: e.toString()),
);
}
await handleError(
emit: emit,
action: () async {
final result = await _getHomeShifts.call();
final name = await _repository.getStaffName();
if (isClosed) return;
emit(
state.copyWith(
status: HomeStatus.loaded,
todayShifts: result.today,
tomorrowShifts: result.tomorrow,
recommendedShifts: result.recommended,
staffName: name,
// Mock profile status for now, ideally fetched from a user repository
isProfileComplete: false,
),
);
},
onError: (String errorKey) {
if (isClosed) return state; // Avoid state emission if closed, though emit handles it gracefully usually
return state.copyWith(status: HomeStatus.error, errorMessage: errorKey);
},
);
}
void toggleAutoMatch(bool enabled) {
emit(state.copyWith(autoMatchEnabled: enabled));
}

View File

@@ -190,7 +190,7 @@ class RecommendedShiftCard extends StatelessWidget {
const SizedBox(width: 4),
Expanded(
child: Text(
shift.locationAddress ?? shift.location,
shift.locationAddress,
style: const TextStyle(
fontSize: 12,
color: UiColors.mutedForeground,