feat: Add file path management for certificate uploads in the mobile app
This commit is contained in:
@@ -19,6 +19,10 @@ class CertificateUploadCubit extends Cubit<CertificateUploadState>
|
|||||||
emit(state.copyWith(isAttested: value));
|
emit(state.copyWith(isAttested: value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setSelectedFilePath(String? filePath) {
|
||||||
|
emit(state.copyWith(selectedFilePath: filePath));
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> deleteCertificate(ComplianceType type) async {
|
Future<void> deleteCertificate(ComplianceType type) async {
|
||||||
emit(state.copyWith(status: CertificateUploadStatus.uploading));
|
emit(state.copyWith(status: CertificateUploadStatus.uploading));
|
||||||
await handleError(
|
await handleError(
|
||||||
|
|||||||
@@ -7,24 +7,28 @@ class CertificateUploadState extends Equatable {
|
|||||||
const CertificateUploadState({
|
const CertificateUploadState({
|
||||||
this.status = CertificateUploadStatus.initial,
|
this.status = CertificateUploadStatus.initial,
|
||||||
this.isAttested = false,
|
this.isAttested = false,
|
||||||
|
this.selectedFilePath,
|
||||||
this.updatedCertificate,
|
this.updatedCertificate,
|
||||||
this.errorMessage,
|
this.errorMessage,
|
||||||
});
|
});
|
||||||
|
|
||||||
final CertificateUploadStatus status;
|
final CertificateUploadStatus status;
|
||||||
final bool isAttested;
|
final bool isAttested;
|
||||||
|
final String? selectedFilePath;
|
||||||
final StaffCertificate? updatedCertificate;
|
final StaffCertificate? updatedCertificate;
|
||||||
final String? errorMessage;
|
final String? errorMessage;
|
||||||
|
|
||||||
CertificateUploadState copyWith({
|
CertificateUploadState copyWith({
|
||||||
CertificateUploadStatus? status,
|
CertificateUploadStatus? status,
|
||||||
bool? isAttested,
|
bool? isAttested,
|
||||||
|
String? selectedFilePath,
|
||||||
StaffCertificate? updatedCertificate,
|
StaffCertificate? updatedCertificate,
|
||||||
String? errorMessage,
|
String? errorMessage,
|
||||||
}) {
|
}) {
|
||||||
return CertificateUploadState(
|
return CertificateUploadState(
|
||||||
status: status ?? this.status,
|
status: status ?? this.status,
|
||||||
isAttested: isAttested ?? this.isAttested,
|
isAttested: isAttested ?? this.isAttested,
|
||||||
|
selectedFilePath: selectedFilePath ?? this.selectedFilePath,
|
||||||
updatedCertificate: updatedCertificate ?? this.updatedCertificate,
|
updatedCertificate: updatedCertificate ?? this.updatedCertificate,
|
||||||
errorMessage: errorMessage ?? this.errorMessage,
|
errorMessage: errorMessage ?? this.errorMessage,
|
||||||
);
|
);
|
||||||
@@ -34,6 +38,7 @@ class CertificateUploadState extends Equatable {
|
|||||||
List<Object?> get props => <Object?>[
|
List<Object?> get props => <Object?>[
|
||||||
status,
|
status,
|
||||||
isAttested,
|
isAttested,
|
||||||
|
selectedFilePath,
|
||||||
updatedCertificate,
|
updatedCertificate,
|
||||||
errorMessage,
|
errorMessage,
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ class CertificateUploadPage extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _CertificateUploadPageState extends State<CertificateUploadPage> {
|
class _CertificateUploadPageState extends State<CertificateUploadPage> {
|
||||||
String? _selectedFilePath;
|
|
||||||
DateTime? _selectedExpiryDate;
|
DateTime? _selectedExpiryDate;
|
||||||
final TextEditingController _issuerController = TextEditingController();
|
final TextEditingController _issuerController = TextEditingController();
|
||||||
final TextEditingController _numberController = TextEditingController();
|
final TextEditingController _numberController = TextEditingController();
|
||||||
@@ -37,16 +36,19 @@ class _CertificateUploadPageState extends State<CertificateUploadPage> {
|
|||||||
|
|
||||||
bool get _isNewCertificate => widget.certificate == null;
|
bool get _isNewCertificate => widget.certificate == null;
|
||||||
|
|
||||||
|
late CertificateUploadCubit _cubit;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
_cubit = Modular.get<CertificateUploadCubit>();
|
||||||
|
|
||||||
if (widget.certificate != null) {
|
if (widget.certificate != null) {
|
||||||
_selectedExpiryDate = widget.certificate!.expiryDate;
|
_selectedExpiryDate = widget.certificate!.expiryDate;
|
||||||
_issuerController.text = widget.certificate!.issuer ?? '';
|
_issuerController.text = widget.certificate!.issuer ?? '';
|
||||||
_numberController.text = widget.certificate!.certificateNumber ?? '';
|
_numberController.text = widget.certificate!.certificateNumber ?? '';
|
||||||
_nameController.text = widget.certificate!.name;
|
_nameController.text = widget.certificate!.name;
|
||||||
_selectedType = widget.certificate!.certificationType;
|
_selectedType = widget.certificate!.certificationType;
|
||||||
_selectedFilePath = widget.certificate?.certificateUrl;
|
|
||||||
} else {
|
} else {
|
||||||
_selectedType = ComplianceType.other;
|
_selectedType = ComplianceType.other;
|
||||||
}
|
}
|
||||||
@@ -82,9 +84,7 @@ class _CertificateUploadPageState extends State<CertificateUploadPage> {
|
|||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setState(() {
|
_cubit.setSelectedFilePath(path);
|
||||||
_selectedFilePath = path;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,7 +148,9 @@ class _CertificateUploadPageState extends State<CertificateUploadPage> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocProvider<CertificateUploadCubit>.value(
|
return BlocProvider<CertificateUploadCubit>.value(
|
||||||
value: Modular.get<CertificateUploadCubit>(),
|
value: _cubit..setSelectedFilePath(
|
||||||
|
widget.certificate?.certificateUrl,
|
||||||
|
),
|
||||||
child: BlocConsumer<CertificateUploadCubit, CertificateUploadState>(
|
child: BlocConsumer<CertificateUploadCubit, CertificateUploadState>(
|
||||||
listener: (BuildContext context, CertificateUploadState state) {
|
listener: (BuildContext context, CertificateUploadState state) {
|
||||||
if (state.status == CertificateUploadStatus.success) {
|
if (state.status == CertificateUploadStatus.success) {
|
||||||
@@ -209,7 +211,7 @@ class _CertificateUploadPageState extends State<CertificateUploadPage> {
|
|||||||
),
|
),
|
||||||
const SizedBox(height: UiConstants.space2),
|
const SizedBox(height: UiConstants.space2),
|
||||||
FileSelector(
|
FileSelector(
|
||||||
selectedFilePath: _selectedFilePath,
|
selectedFilePath: state.selectedFilePath,
|
||||||
onTap: _pickFile,
|
onTap: _pickFile,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -220,7 +222,7 @@ class _CertificateUploadPageState extends State<CertificateUploadPage> {
|
|||||||
padding: const EdgeInsets.all(UiConstants.space5),
|
padding: const EdgeInsets.all(UiConstants.space5),
|
||||||
child: CertificateUploadActions(
|
child: CertificateUploadActions(
|
||||||
isAttested: state.isAttested,
|
isAttested: state.isAttested,
|
||||||
isFormValid: _selectedFilePath != null &&
|
isFormValid: state.selectedFilePath != null &&
|
||||||
state.isAttested &&
|
state.isAttested &&
|
||||||
_nameController.text.isNotEmpty,
|
_nameController.text.isNotEmpty,
|
||||||
isUploading: state.status == CertificateUploadStatus.uploading,
|
isUploading: state.status == CertificateUploadStatus.uploading,
|
||||||
@@ -228,7 +230,7 @@ class _CertificateUploadPageState extends State<CertificateUploadPage> {
|
|||||||
onUploadPressed: () {
|
onUploadPressed: () {
|
||||||
final String? err = _validatePdfFile(
|
final String? err = _validatePdfFile(
|
||||||
context,
|
context,
|
||||||
_selectedFilePath!,
|
state.selectedFilePath!,
|
||||||
);
|
);
|
||||||
if (err != null) {
|
if (err != null) {
|
||||||
UiSnackbar.show(
|
UiSnackbar.show(
|
||||||
@@ -244,7 +246,7 @@ class _CertificateUploadPageState extends State<CertificateUploadPage> {
|
|||||||
UploadCertificateParams(
|
UploadCertificateParams(
|
||||||
certificationType: _selectedType!,
|
certificationType: _selectedType!,
|
||||||
name: _nameController.text,
|
name: _nameController.text,
|
||||||
filePath: _selectedFilePath!,
|
filePath: state.selectedFilePath!,
|
||||||
expiryDate: _selectedExpiryDate,
|
expiryDate: _selectedExpiryDate,
|
||||||
issuer: _issuerController.text,
|
issuer: _issuerController.text,
|
||||||
certificateNumber: _numberController.text,
|
certificateNumber: _numberController.text,
|
||||||
|
|||||||
Reference in New Issue
Block a user