feat: Add file path management for certificate uploads in the mobile app

This commit is contained in:
Achintha Isuru
2026-03-01 21:03:01 -05:00
parent b0abd68c2e
commit 973b8b8ac3
3 changed files with 21 additions and 10 deletions

View File

@@ -19,6 +19,10 @@ class CertificateUploadCubit extends Cubit<CertificateUploadState>
emit(state.copyWith(isAttested: value));
}
void setSelectedFilePath(String? filePath) {
emit(state.copyWith(selectedFilePath: filePath));
}
Future<void> deleteCertificate(ComplianceType type) async {
emit(state.copyWith(status: CertificateUploadStatus.uploading));
await handleError(

View File

@@ -7,24 +7,28 @@ class CertificateUploadState extends Equatable {
const CertificateUploadState({
this.status = CertificateUploadStatus.initial,
this.isAttested = false,
this.selectedFilePath,
this.updatedCertificate,
this.errorMessage,
});
final CertificateUploadStatus status;
final bool isAttested;
final String? selectedFilePath;
final StaffCertificate? updatedCertificate;
final String? errorMessage;
CertificateUploadState copyWith({
CertificateUploadStatus? status,
bool? isAttested,
String? selectedFilePath,
StaffCertificate? updatedCertificate,
String? errorMessage,
}) {
return CertificateUploadState(
status: status ?? this.status,
isAttested: isAttested ?? this.isAttested,
selectedFilePath: selectedFilePath ?? this.selectedFilePath,
updatedCertificate: updatedCertificate ?? this.updatedCertificate,
errorMessage: errorMessage ?? this.errorMessage,
);
@@ -34,6 +38,7 @@ class CertificateUploadState extends Equatable {
List<Object?> get props => <Object?>[
status,
isAttested,
selectedFilePath,
updatedCertificate,
errorMessage,
];

View File

@@ -25,7 +25,6 @@ class CertificateUploadPage extends StatefulWidget {
}
class _CertificateUploadPageState extends State<CertificateUploadPage> {
String? _selectedFilePath;
DateTime? _selectedExpiryDate;
final TextEditingController _issuerController = TextEditingController();
final TextEditingController _numberController = TextEditingController();
@@ -37,16 +36,19 @@ class _CertificateUploadPageState extends State<CertificateUploadPage> {
bool get _isNewCertificate => widget.certificate == null;
late CertificateUploadCubit _cubit;
@override
void initState() {
super.initState();
_cubit = Modular.get<CertificateUploadCubit>();
if (widget.certificate != null) {
_selectedExpiryDate = widget.certificate!.expiryDate;
_issuerController.text = widget.certificate!.issuer ?? '';
_numberController.text = widget.certificate!.certificateNumber ?? '';
_nameController.text = widget.certificate!.name;
_selectedType = widget.certificate!.certificationType;
_selectedFilePath = widget.certificate?.certificateUrl;
} else {
_selectedType = ComplianceType.other;
}
@@ -82,9 +84,7 @@ class _CertificateUploadPageState extends State<CertificateUploadPage> {
);
return;
}
setState(() {
_selectedFilePath = path;
});
_cubit.setSelectedFilePath(path);
}
}
@@ -148,7 +148,9 @@ class _CertificateUploadPageState extends State<CertificateUploadPage> {
@override
Widget build(BuildContext context) {
return BlocProvider<CertificateUploadCubit>.value(
value: Modular.get<CertificateUploadCubit>(),
value: _cubit..setSelectedFilePath(
widget.certificate?.certificateUrl,
),
child: BlocConsumer<CertificateUploadCubit, CertificateUploadState>(
listener: (BuildContext context, CertificateUploadState state) {
if (state.status == CertificateUploadStatus.success) {
@@ -209,7 +211,7 @@ class _CertificateUploadPageState extends State<CertificateUploadPage> {
),
const SizedBox(height: UiConstants.space2),
FileSelector(
selectedFilePath: _selectedFilePath,
selectedFilePath: state.selectedFilePath,
onTap: _pickFile,
),
],
@@ -220,7 +222,7 @@ class _CertificateUploadPageState extends State<CertificateUploadPage> {
padding: const EdgeInsets.all(UiConstants.space5),
child: CertificateUploadActions(
isAttested: state.isAttested,
isFormValid: _selectedFilePath != null &&
isFormValid: state.selectedFilePath != null &&
state.isAttested &&
_nameController.text.isNotEmpty,
isUploading: state.status == CertificateUploadStatus.uploading,
@@ -228,7 +230,7 @@ class _CertificateUploadPageState extends State<CertificateUploadPage> {
onUploadPressed: () {
final String? err = _validatePdfFile(
context,
_selectedFilePath!,
state.selectedFilePath!,
);
if (err != null) {
UiSnackbar.show(
@@ -244,7 +246,7 @@ class _CertificateUploadPageState extends State<CertificateUploadPage> {
UploadCertificateParams(
certificationType: _selectedType!,
name: _nameController.text,
filePath: _selectedFilePath!,
filePath: state.selectedFilePath!,
expiryDate: _selectedExpiryDate,
issuer: _issuerController.text,
certificateNumber: _numberController.text,