diff --git a/lib/features/contact_us/contact_us_view_model.dart b/lib/features/contact_us/contact_us_view_model.dart index 323eb782..40cab14c 100644 --- a/lib/features/contact_us/contact_us_view_model.dart +++ b/lib/features/contact_us/contact_us_view_model.dart @@ -15,6 +15,19 @@ import 'package:hmg_patient_app_new/services/error_handler_service.dart'; import 'package:hmg_patient_app_new/widgets/loader/bottomsheet_loader.dart'; import 'package:permission_handler/permission_handler.dart'; +/// Class to store feedback attachment data +class FeedbackAttachment { + final String base64String; + final File file; + final String fileName; + + FeedbackAttachment({ + required this.base64String, + required this.file, + required this.fileName, + }); +} + class ContactUsViewModel extends ChangeNotifier { ContactUsRepo contactUsRepo; ErrorHandlerService errorHandlerService; @@ -35,7 +48,7 @@ class ContactUsViewModel extends ChangeNotifier { String? chatRequestID; - List feedbackAttachmentList = []; + List feedbackAttachmentList = []; List cocItemsList = []; bool isCOCItemsListLoading = false; @@ -168,13 +181,20 @@ class ContactUsViewModel extends ChangeNotifier { notifyListeners(); } - addFeedbackAttachment(String attachmentPath) { - feedbackAttachmentList.add(attachmentPath); + addFeedbackAttachment(String base64String, File file) { + // Extract filename from file path + final fileName = file.path.split('/').last; + + feedbackAttachmentList.add(FeedbackAttachment( + base64String: base64String, + file: file, + fileName: fileName, + )); notifyListeners(); } - removeFeedbackAttachment(String attachmentPath) { - feedbackAttachmentList.remove(attachmentPath); + removeFeedbackAttachment(FeedbackAttachment attachment) { + feedbackAttachmentList.remove(attachment); notifyListeners(); } @@ -282,7 +302,7 @@ class ContactUsViewModel extends ChangeNotifier { Future insertCOCItem({required String subject, required String message, Function(dynamic)? onSuccess, Function(String)? onError}) async { RequestInsertCOCItem requestInsertCOCItem = RequestInsertCOCItem(); - requestInsertCOCItem.attachment = feedbackAttachmentList.isNotEmpty ? feedbackAttachmentList.first : ""; + requestInsertCOCItem.attachment = feedbackAttachmentList.isNotEmpty ? feedbackAttachmentList.first.base64String : ""; requestInsertCOCItem.title = subject; requestInsertCOCItem.details = message; requestInsertCOCItem.cOCTypeName = selectedFeedbackType.id.toString(); @@ -291,7 +311,7 @@ class ContactUsViewModel extends ChangeNotifier { requestInsertCOCItem.isUserLoggedIn = true; requestInsertCOCItem.projectID = 0; requestInsertCOCItem.patientName = "${appState.getAuthenticatedUser()!.firstName!} ${appState.getAuthenticatedUser()!.lastName!}"; - requestInsertCOCItem.fileName = "Image 1"; + requestInsertCOCItem.fileName = feedbackAttachmentList.isNotEmpty ? feedbackAttachmentList.first.fileName : ""; requestInsertCOCItem.appVersion = ApiConsts.appVersionID; requestInsertCOCItem.uILanguage = appState.isArabic() ? "ar" : "en"; requestInsertCOCItem.browserInfo = Platform.localHostname; diff --git a/lib/presentation/contact_us/feedback_page.dart b/lib/presentation/contact_us/feedback_page.dart index 32359fef..251c720d 100644 --- a/lib/presentation/contact_us/feedback_page.dart +++ b/lib/presentation/contact_us/feedback_page.dart @@ -354,11 +354,10 @@ class FeedbackPage extends StatelessWidget { ImageOptions.showImageOptionsNew( context, true, - (String image, file) { - print(image); - print(file); - // Navigator.pop(context); - contactUsViewModel.addFeedbackAttachment(image); + (String base64Image, file) { + // base64Image: The base64-encoded image string + // file: The File object + contactUsViewModel.addFeedbackAttachment(base64Image, file); }, ); }, @@ -385,25 +384,31 @@ class FeedbackPage extends StatelessWidget { child: ListView.builder( padding: EdgeInsets.all(16.h), shrinkWrap: true, + physics: NeverScrollableScrollPhysics(), itemCount: contactUsViewModel.feedbackAttachmentList.length, itemBuilder: (BuildContext context, int index) { + final attachment = contactUsViewModel.feedbackAttachmentList[index]; return Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.start, children: [ - Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Icon( - Icons.attach_file, - color: Color(0xff2B353E), - ), - SizedBox(width: 8.w), - "Image ${index + 1}".toText14().paddingOnly(bottom: 8.h), - ], + Expanded( + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Icon( + Icons.attach_file, + color: Color(0xff2B353E), + ), + SizedBox(width: 8.w), + Expanded( + child: attachment.fileName.toText14().paddingOnly(bottom: 8.h), + ), + ], + ), ), Utils.buildSvgWithAssets(icon: AppAssets.cancel_circle_icon).onPress(() { - contactUsViewModel.removeFeedbackAttachment(contactUsViewModel.feedbackAttachmentList[index]); + contactUsViewModel.removeFeedbackAttachment(attachment); }), ], ); diff --git a/lib/widgets/attachment_options.dart b/lib/widgets/attachment_options.dart index bbc0bc6d..db4164a3 100644 --- a/lib/widgets/attachment_options.dart +++ b/lib/widgets/attachment_options.dart @@ -48,7 +48,8 @@ class AttachmentOptions extends StatelessWidget { ).onPress(() async { await onGalleryTap(); }), - if (!showFilesOption) SizedBox(height: 16.h), + // if (!showFilesOption) commented because the ui issue. + SizedBox(height: 16.h), if (showFilesOption) checkInOptionCard( appState,