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,28 +1,38 @@
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:krow_core/core.dart';
import 'package:krow_domain/krow_domain.dart';
import '../../../domain/usecases/get_certificates_usecase.dart';
import 'certificates_state.dart';
class CertificatesCubit extends Cubit<CertificatesState> {
class CertificatesCubit extends Cubit<CertificatesState>
with BlocErrorHandler<CertificatesState> {
final GetCertificatesUseCase _getCertificatesUseCase;
CertificatesCubit(this._getCertificatesUseCase) : super(const CertificatesState()) {
CertificatesCubit(this._getCertificatesUseCase)
: super(const CertificatesState()) {
loadCertificates();
}
Future<void> loadCertificates() async {
emit(state.copyWith(status: CertificatesStatus.loading));
try {
final List<StaffDocument> certificates = await _getCertificatesUseCase();
emit(state.copyWith(
status: CertificatesStatus.success,
certificates: certificates,
));
} catch (e) {
emit(state.copyWith(
status: CertificatesStatus.failure,
errorMessage: e.toString(),
));
}
await handleError(
emit: emit,
action: () async {
final List<StaffDocument> certificates =
await _getCertificatesUseCase();
emit(
state.copyWith(
status: CertificatesStatus.success,
certificates: certificates,
),
);
},
onError:
(String errorKey) => state.copyWith(
status: CertificatesStatus.failure,
errorMessage: errorKey,
),
);
}
}

View File

@@ -49,6 +49,7 @@ class DocumentsRepositoryImpl implements DocumentsRepository {
),
];
/*
try {
final QueryResult<ListStaffDocumentsByStaffIdData,
ListStaffDocumentsByStaffIdVariables> result =
@@ -63,6 +64,7 @@ class DocumentsRepositoryImpl implements DocumentsRepository {
} catch (e) {
throw Exception('Failed to fetch documents: $e');
}
*/
}
domain.StaffDocument _mapToDomain(

View File

@@ -1,26 +1,34 @@
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:krow_core/core.dart';
import 'package:krow_domain/krow_domain.dart';
import '../../../domain/usecases/get_documents_usecase.dart';
import 'documents_state.dart';
class DocumentsCubit extends Cubit<DocumentsState> {
class DocumentsCubit extends Cubit<DocumentsState>
with BlocErrorHandler<DocumentsState> {
final GetDocumentsUseCase _getDocumentsUseCase;
DocumentsCubit(this._getDocumentsUseCase) : super(const DocumentsState());
Future<void> loadDocuments() async {
emit(state.copyWith(status: DocumentsStatus.loading));
try {
final List<StaffDocument> documents = await _getDocumentsUseCase();
emit(state.copyWith(
status: DocumentsStatus.success,
documents: documents,
));
} catch (e) {
emit(state.copyWith(
status: DocumentsStatus.failure,
errorMessage: e.toString(),
));
}
await handleError(
emit: emit,
action: () async {
final List<StaffDocument> documents = await _getDocumentsUseCase();
emit(
state.copyWith(
status: DocumentsStatus.success,
documents: documents,
),
);
},
onError:
(String errorKey) => state.copyWith(
status: DocumentsStatus.failure,
errorMessage: errorKey,
),
);
}
}

View File

@@ -1,11 +1,12 @@
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:krow_core/core.dart';
import 'package:krow_domain/krow_domain.dart';
import 'package:uuid/uuid.dart';
import '../../../domain/usecases/submit_i9_form_usecase.dart';
import 'form_i9_state.dart';
class FormI9Cubit extends Cubit<FormI9State> {
class FormI9Cubit extends Cubit<FormI9State> with BlocErrorHandler<FormI9State> {
final SubmitI9FormUseCase _submitI9FormUseCase;
String _formId = '';
@@ -16,31 +17,33 @@ class FormI9Cubit extends Cubit<FormI9State> {
emit(const FormI9State()); // Reset to empty if no form
return;
}
final Map<String, dynamic> data = form.formData;
_formId = form.id;
emit(FormI9State(
firstName: data['firstName'] as String? ?? '',
lastName: data['lastName'] as String? ?? '',
middleInitial: data['middleInitial'] as String? ?? '',
otherLastNames: data['otherLastNames'] as String? ?? '',
dob: data['dob'] as String? ?? '',
ssn: data['ssn'] as String? ?? '',
email: data['email'] as String? ?? '',
phone: data['phone'] as String? ?? '',
address: data['address'] as String? ?? '',
aptNumber: data['aptNumber'] as String? ?? '',
city: data['city'] as String? ?? '',
state: data['state'] as String? ?? '',
zipCode: data['zipCode'] as String? ?? '',
citizenshipStatus: data['citizenshipStatus'] as String? ?? '',
uscisNumber: data['uscisNumber'] as String? ?? '',
admissionNumber: data['admissionNumber'] as String? ?? '',
passportNumber: data['passportNumber'] as String? ?? '',
countryIssuance: data['countryIssuance'] as String? ?? '',
preparerUsed: data['preparerUsed'] as bool? ?? false,
signature: data['signature'] as String? ?? '',
));
emit(
FormI9State(
firstName: data['firstName'] as String? ?? '',
lastName: data['lastName'] as String? ?? '',
middleInitial: data['middleInitial'] as String? ?? '',
otherLastNames: data['otherLastNames'] as String? ?? '',
dob: data['dob'] as String? ?? '',
ssn: data['ssn'] as String? ?? '',
email: data['email'] as String? ?? '',
phone: data['phone'] as String? ?? '',
address: data['address'] as String? ?? '',
aptNumber: data['aptNumber'] as String? ?? '',
city: data['city'] as String? ?? '',
state: data['state'] as String? ?? '',
zipCode: data['zipCode'] as String? ?? '',
citizenshipStatus: data['citizenshipStatus'] as String? ?? '',
uscisNumber: data['uscisNumber'] as String? ?? '',
admissionNumber: data['admissionNumber'] as String? ?? '',
passportNumber: data['passportNumber'] as String? ?? '',
countryIssuance: data['countryIssuance'] as String? ?? '',
preparerUsed: data['preparerUsed'] as bool? ?? false,
signature: data['signature'] as String? ?? '',
),
);
}
void nextStep(int totalSteps) {
@@ -58,8 +61,10 @@ class FormI9Cubit extends Cubit<FormI9State> {
// Personal Info
void firstNameChanged(String value) => emit(state.copyWith(firstName: value));
void lastNameChanged(String value) => emit(state.copyWith(lastName: value));
void middleInitialChanged(String value) => emit(state.copyWith(middleInitial: value));
void otherLastNamesChanged(String value) => emit(state.copyWith(otherLastNames: value));
void middleInitialChanged(String value) =>
emit(state.copyWith(middleInitial: value));
void otherLastNamesChanged(String value) =>
emit(state.copyWith(otherLastNames: value));
void dobChanged(String value) => emit(state.copyWith(dob: value));
void ssnChanged(String value) => emit(state.copyWith(ssn: value));
void emailChanged(String value) => emit(state.copyWith(email: value));
@@ -73,55 +78,65 @@ class FormI9Cubit extends Cubit<FormI9State> {
void zipCodeChanged(String value) => emit(state.copyWith(zipCode: value));
// Citizenship
void citizenshipStatusChanged(String value) => emit(state.copyWith(citizenshipStatus: value));
void uscisNumberChanged(String value) => emit(state.copyWith(uscisNumber: value));
void admissionNumberChanged(String value) => emit(state.copyWith(admissionNumber: value));
void passportNumberChanged(String value) => emit(state.copyWith(passportNumber: value));
void countryIssuanceChanged(String value) => emit(state.copyWith(countryIssuance: value));
void citizenshipStatusChanged(String value) =>
emit(state.copyWith(citizenshipStatus: value));
void uscisNumberChanged(String value) =>
emit(state.copyWith(uscisNumber: value));
void admissionNumberChanged(String value) =>
emit(state.copyWith(admissionNumber: value));
void passportNumberChanged(String value) =>
emit(state.copyWith(passportNumber: value));
void countryIssuanceChanged(String value) =>
emit(state.copyWith(countryIssuance: value));
// Signature
void preparerUsedChanged(bool value) => emit(state.copyWith(preparerUsed: value));
void preparerUsedChanged(bool value) =>
emit(state.copyWith(preparerUsed: value));
void signatureChanged(String value) => emit(state.copyWith(signature: value));
Future<void> submit() async {
emit(state.copyWith(status: FormI9Status.submitting));
try {
final Map<String, dynamic> formData = {
'firstName': state.firstName,
'lastName': state.lastName,
'middleInitial': state.middleInitial,
'otherLastNames': state.otherLastNames,
'dob': state.dob,
'ssn': state.ssn,
'email': state.email,
'phone': state.phone,
'address': state.address,
'aptNumber': state.aptNumber,
'city': state.city,
'state': state.state,
'zipCode': state.zipCode,
'citizenshipStatus': state.citizenshipStatus,
'uscisNumber': state.uscisNumber,
'admissionNumber': state.admissionNumber,
'passportNumber': state.passportNumber,
'countryIssuance': state.countryIssuance,
'preparerUsed': state.preparerUsed,
'signature': state.signature,
};
await handleError(
emit: emit,
action: () async {
final Map<String, dynamic> formData = {
'firstName': state.firstName,
'lastName': state.lastName,
'middleInitial': state.middleInitial,
'otherLastNames': state.otherLastNames,
'dob': state.dob,
'ssn': state.ssn,
'email': state.email,
'phone': state.phone,
'address': state.address,
'aptNumber': state.aptNumber,
'city': state.city,
'state': state.state,
'zipCode': state.zipCode,
'citizenshipStatus': state.citizenshipStatus,
'uscisNumber': state.uscisNumber,
'admissionNumber': state.admissionNumber,
'passportNumber': state.passportNumber,
'countryIssuance': state.countryIssuance,
'preparerUsed': state.preparerUsed,
'signature': state.signature,
};
final I9TaxForm form = I9TaxForm(
id: _formId.isNotEmpty ? _formId : const Uuid().v4(),
title: 'Form I-9',
formData: formData,
);
final I9TaxForm form = I9TaxForm(
id: _formId.isNotEmpty ? _formId : const Uuid().v4(),
title: 'Form I-9',
formData: formData,
);
await _submitI9FormUseCase(form);
emit(state.copyWith(status: FormI9Status.success));
} catch (e) {
emit(state.copyWith(
status: FormI9Status.failure,
errorMessage: e.toString(),
));
}
await _submitI9FormUseCase(form);
emit(state.copyWith(status: FormI9Status.success));
},
onError:
(String errorKey) => state.copyWith(
status: FormI9Status.failure,
errorMessage: errorKey,
),
);
}
}

View File

@@ -1,26 +1,29 @@
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:krow_core/core.dart';
import 'package:krow_domain/krow_domain.dart';
import '../../../domain/usecases/get_tax_forms_usecase.dart';
import 'tax_forms_state.dart';
class TaxFormsCubit extends Cubit<TaxFormsState> {
class TaxFormsCubit extends Cubit<TaxFormsState>
with BlocErrorHandler<TaxFormsState> {
final GetTaxFormsUseCase _getTaxFormsUseCase;
TaxFormsCubit(this._getTaxFormsUseCase) : super(const TaxFormsState());
Future<void> loadTaxForms() async {
emit(state.copyWith(status: TaxFormsStatus.loading));
try {
final List<TaxForm> forms = await _getTaxFormsUseCase();
emit(state.copyWith(
status: TaxFormsStatus.success,
forms: forms,
));
} catch (e) {
emit(state.copyWith(
status: TaxFormsStatus.failure,
errorMessage: e.toString(),
));
}
await handleError(
emit: emit,
action: () async {
final List<TaxForm> forms = await _getTaxFormsUseCase();
emit(state.copyWith(status: TaxFormsStatus.success, forms: forms));
},
onError:
(String errorKey) => state.copyWith(
status: TaxFormsStatus.failure,
errorMessage: errorKey,
),
);
}
}

View File

@@ -1,11 +1,12 @@
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:krow_core/core.dart';
import 'package:krow_domain/krow_domain.dart';
import 'package:uuid/uuid.dart';
import '../../../domain/usecases/submit_w4_form_usecase.dart';
import 'form_w4_state.dart';
class FormW4Cubit extends Cubit<FormW4State> {
class FormW4Cubit extends Cubit<FormW4State> with BlocErrorHandler<FormW4State> {
final SubmitW4FormUseCase _submitW4FormUseCase;
String _formId = '';
@@ -16,31 +17,33 @@ class FormW4Cubit extends Cubit<FormW4State> {
emit(const FormW4State()); // Reset
return;
}
final Map<String, dynamic> data = form.formData;
_formId = form.id;
// Combine address parts if needed, or take existing
final String city = data['city'] as String? ?? '';
final String stateVal = data['state'] as String? ?? '';
final String zip = data['zipCode'] as String? ?? '';
final String cityStateZip = '$city, $stateVal $zip'.trim();
emit(FormW4State(
firstName: data['firstName'] as String? ?? '',
lastName: data['lastName'] as String? ?? '',
ssn: data['ssn'] as String? ?? '',
address: data['address'] as String? ?? '',
cityStateZip: cityStateZip.contains(',') ? cityStateZip : '',
filingStatus: data['filingStatus'] as String? ?? '',
multipleJobs: data['multipleJobs'] as bool? ?? false,
qualifyingChildren: data['qualifyingChildren'] as int? ?? 0,
otherDependents: data['otherDependents'] as int? ?? 0,
otherIncome: data['otherIncome'] as String? ?? '',
deductions: data['deductions'] as String? ?? '',
extraWithholding: data['extraWithholding'] as String? ?? '',
signature: data['signature'] as String? ?? '',
));
emit(
FormW4State(
firstName: data['firstName'] as String? ?? '',
lastName: data['lastName'] as String? ?? '',
ssn: data['ssn'] as String? ?? '',
address: data['address'] as String? ?? '',
cityStateZip: cityStateZip.contains(',') ? cityStateZip : '',
filingStatus: data['filingStatus'] as String? ?? '',
multipleJobs: data['multipleJobs'] as bool? ?? false,
qualifyingChildren: data['qualifyingChildren'] as int? ?? 0,
otherDependents: data['otherDependents'] as int? ?? 0,
otherIncome: data['otherIncome'] as String? ?? '',
deductions: data['deductions'] as String? ?? '',
extraWithholding: data['extraWithholding'] as String? ?? '',
signature: data['signature'] as String? ?? '',
),
);
}
void nextStep(int totalSteps) {
@@ -62,52 +65,65 @@ class FormW4Cubit extends Cubit<FormW4State> {
void lastNameChanged(String value) => emit(state.copyWith(lastName: value));
void ssnChanged(String value) => emit(state.copyWith(ssn: value));
void addressChanged(String value) => emit(state.copyWith(address: value));
void cityStateZipChanged(String value) => emit(state.copyWith(cityStateZip: value));
void cityStateZipChanged(String value) =>
emit(state.copyWith(cityStateZip: value));
// Form Data
void filingStatusChanged(String value) => emit(state.copyWith(filingStatus: value));
void multipleJobsChanged(bool value) => emit(state.copyWith(multipleJobs: value));
void qualifyingChildrenChanged(int value) => emit(state.copyWith(qualifyingChildren: value));
void otherDependentsChanged(int value) => emit(state.copyWith(otherDependents: value));
void filingStatusChanged(String value) =>
emit(state.copyWith(filingStatus: value));
void multipleJobsChanged(bool value) =>
emit(state.copyWith(multipleJobs: value));
void qualifyingChildrenChanged(int value) =>
emit(state.copyWith(qualifyingChildren: value));
void otherDependentsChanged(int value) =>
emit(state.copyWith(otherDependents: value));
// Adjustments
void otherIncomeChanged(String value) => emit(state.copyWith(otherIncome: value));
void deductionsChanged(String value) => emit(state.copyWith(deductions: value));
void extraWithholdingChanged(String value) => emit(state.copyWith(extraWithholding: value));
void otherIncomeChanged(String value) =>
emit(state.copyWith(otherIncome: value));
void deductionsChanged(String value) =>
emit(state.copyWith(deductions: value));
void extraWithholdingChanged(String value) =>
emit(state.copyWith(extraWithholding: value));
void signatureChanged(String value) => emit(state.copyWith(signature: value));
Future<void> submit() async {
emit(state.copyWith(status: FormW4Status.submitting));
try {
final Map<String, dynamic> formData = {
'firstName': state.firstName,
'lastName': state.lastName,
'ssn': state.ssn,
'address': state.address,
'cityStateZip': state.cityStateZip, // Note: Repository should split this if needed.
'filingStatus': state.filingStatus,
'multipleJobs': state.multipleJobs,
'qualifyingChildren': state.qualifyingChildren,
'otherDependents': state.otherDependents,
'otherIncome': state.otherIncome,
'deductions': state.deductions,
'extraWithholding': state.extraWithholding,
'signature': state.signature,
};
await handleError(
emit: emit,
action: () async {
final Map<String, dynamic> formData = {
'firstName': state.firstName,
'lastName': state.lastName,
'ssn': state.ssn,
'address': state.address,
'cityStateZip':
state.cityStateZip, // Note: Repository should split this if needed.
'filingStatus': state.filingStatus,
'multipleJobs': state.multipleJobs,
'qualifyingChildren': state.qualifyingChildren,
'otherDependents': state.otherDependents,
'otherIncome': state.otherIncome,
'deductions': state.deductions,
'extraWithholding': state.extraWithholding,
'signature': state.signature,
};
final W4TaxForm form = W4TaxForm(
id: _formId.isNotEmpty ? _formId : const Uuid().v4(),
title: 'Form W-4',
formData: formData,
);
final W4TaxForm form = W4TaxForm(
id: _formId.isNotEmpty ? _formId : const Uuid().v4(),
title: 'Form W-4',
formData: formData,
);
await _submitW4FormUseCase(form);
emit(state.copyWith(status: FormW4Status.success));
} catch (e) {
emit(state.copyWith(
status: FormW4Status.failure,
errorMessage: e.toString(),
));
}
await _submitW4FormUseCase(form);
emit(state.copyWith(status: FormW4Status.success));
},
onError:
(String errorKey) => state.copyWith(
status: FormW4Status.failure,
errorMessage: errorKey,
),
);
}
}

View File

@@ -147,12 +147,12 @@ class TaxFormsPage extends StatelessWidget {
if (form is I9TaxForm) {
final result = await Modular.to.pushNamed('i9', arguments: form);
if (result == true && context.mounted) {
BlocProvider.of<TaxFormsCubit>(context).loadTaxForms();
await BlocProvider.of<TaxFormsCubit>(context).loadTaxForms();
}
} else if (form is W4TaxForm) {
final result = await Modular.to.pushNamed('w4', arguments: form);
if (result == true && context.mounted) {
BlocProvider.of<TaxFormsCubit>(context).loadTaxForms();
await BlocProvider.of<TaxFormsCubit>(context).loadTaxForms();
}
}
},