uploadReceipt method
Implementation
void uploadReceipt() async {
if (receiptFile.value == null) {
CustomFlashWidget.showFlashMessage(
type: FlashType.error,
title: 'Invalid file',
message: 'Please select a file to upload first',
);
return;
}
try {
loadingDialog();
final fileName = receiptFile.value!.name;
final storageRef =
FirebaseStorage.instance.ref().child('payment/receipts/$fileName');
final uploadTask = storageRef.putData(
await receiptFile.value!.readAsBytes(),
);
await uploadTask.whenComplete(() async {
final downloadURL = await storageRef.getDownloadURL();
receiptUrl.value = downloadURL;
log('Receipt uploaded successfully: $downloadURL');
});
} catch (e) {
log('Error uploading profile image: ${e.toString()}');
CustomFlashWidget.showFlashMessage(
type: FlashType.error,
title: "Error",
message: "Error occurred while uploading ticket",
);
}
closeDialog();
}