import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:hmg_patient_app_new/core/app_assets.dart'; import 'package:hmg_patient_app_new/core/app_state.dart'; import 'package:hmg_patient_app_new/core/dependencies.dart'; import 'package:hmg_patient_app_new/core/utils/date_util.dart'; import 'package:hmg_patient_app_new/core/utils/size_utils.dart'; import 'package:hmg_patient_app_new/core/utils/utils.dart'; import 'package:hmg_patient_app_new/extensions/string_extensions.dart'; import 'package:hmg_patient_app_new/extensions/widget_extensions.dart'; import 'package:hmg_patient_app_new/features/book_appointments/book_appointments_view_model.dart'; import 'package:hmg_patient_app_new/features/contact_us/contact_us_view_model.dart'; import 'package:hmg_patient_app_new/features/contact_us/models/feedback_type.dart'; import 'package:hmg_patient_app_new/features/medical_file/medical_file_view_model.dart'; import 'package:hmg_patient_app_new/features/my_appointments/my_appointments_view_model.dart'; import 'package:hmg_patient_app_new/generated/locale_keys.g.dart'; import 'package:hmg_patient_app_new/presentation/appointments/widgets/appointment_card.dart'; import 'package:hmg_patient_app_new/presentation/contact_us/widgets/feedback_appointment_selection.dart'; import 'package:hmg_patient_app_new/theme/colors.dart'; import 'package:hmg_patient_app_new/widgets/appbar/collapsing_list_view.dart'; import 'package:hmg_patient_app_new/widgets/buttons/custom_button.dart'; import 'package:hmg_patient_app_new/widgets/chip/app_custom_chip_widget.dart'; import 'package:hmg_patient_app_new/widgets/common_bottom_sheet.dart'; import 'package:hmg_patient_app_new/widgets/custom_tab_bar.dart'; import 'package:hmg_patient_app_new/widgets/image_picker.dart'; import 'package:hmg_patient_app_new/widgets/input_widget.dart'; import 'package:hmg_patient_app_new/widgets/loader/bottomsheet_loader.dart'; import 'package:hmg_patient_app_new/widgets/routes/custom_page_route.dart'; import 'package:provider/provider.dart'; class FeedbackPage extends StatelessWidget { FeedbackPage({super.key}); late ContactUsViewModel contactUsViewModel; late MedicalFileViewModel medicalFileViewModel; final TextEditingController subjectTextController = TextEditingController(); final TextEditingController messageTextController = TextEditingController(); @override Widget build(BuildContext context) { contactUsViewModel = Provider.of(context, listen: false); medicalFileViewModel = Provider.of(context, listen: false); return Scaffold( backgroundColor: AppColors.bgScaffoldColor, body: Consumer(builder: (context, contactUsVM, child) { return Column( children: [ Expanded( child: CollapsingListView( isLeading: Navigator.canPop(context), title: LocaleKeys.feedback.tr(), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ SizedBox(height: 16.h), CustomTabBar( activeTextColor: AppColors.primaryRedColor, activeBackgroundColor: AppColors.primaryRedColor.withValues(alpha: .1), tabs: [ CustomTabBarModel(null, "Send".needTranslation), CustomTabBarModel(null, "Status".needTranslation), ], onTabChange: (index) { contactUsViewModel.setIsSendFeedbackTabSelected(index == 0); }, ).paddingSymmetrical(24.h, 0.h), getSelectedTabWidget(context).paddingSymmetrical(24.h, 16.w), ], ), ), ), Container( decoration: RoundedRectangleBorder().toSmoothCornerDecoration( color: AppColors.whiteColor, customBorder: BorderRadius.only( topLeft: Radius.circular(24.h), topRight: Radius.circular(24.h), ), hasShadow: true, ), child: CustomButton( text: LocaleKeys.submit.tr(context: context), onPressed: () async { if (subjectTextController.text.isEmpty) { showCommonBottomSheetWithoutHeight( context, child: Utils.getErrorWidget(loadingText: LocaleKeys.emptySubject.tr(context: context)), ); return; } if (messageTextController.text.isEmpty) { showCommonBottomSheetWithoutHeight( context, child: Utils.getErrorWidget(loadingText: LocaleKeys.emptyMessage.tr(context: context)), ); return; } LoaderBottomSheet.showLoader(loadingText: "Sending Feedback...".needTranslation); contactUsViewModel.insertCOCItem( subject: subjectTextController.text, message: messageTextController.text, onSuccess: (val) { LoaderBottomSheet.hideLoader(); subjectTextController.clear(); messageTextController.clear(); contactUsViewModel.setPatientFeedbackSelectedAppointment(null); showCommonBottomSheetWithoutHeight(context, child: Utils.getSuccessWidget(loadingText: LocaleKeys.success.tr(context: context)), callBackFunc: () { Navigator.pop(context); }); }, onError: (err) { LoaderBottomSheet.hideLoader(); showCommonBottomSheetWithoutHeight( context, child: Utils.getSuccessWidget(loadingText: err), ); }); }, backgroundColor: AppColors.primaryRedColor, borderColor: AppColors.primaryRedColor, textColor: AppColors.whiteColor, fontSize: 16, fontWeight: FontWeight.w500, borderRadius: 12, padding: EdgeInsets.fromLTRB(10, 0, 10, 0), height: 50.h, icon: AppAssets.feedback, iconColor: AppColors.whiteColor, iconSize: 20.h, ).paddingSymmetrical(24.h, 24.h), ), ], ); }), ); } Widget getSelectedTabWidget(BuildContext context) { if (contactUsViewModel.isSendFeedbackTabSelected) { return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ LocaleKeys.likeToHear.tr().toText14(weight: FontWeight.w500), SizedBox(height: 16.h), Container( decoration: RoundedRectangleBorder().toSmoothCornerDecoration( color: AppColors.whiteColor, borderRadius: 16.r, hasShadow: false, ), child: Padding( padding: EdgeInsets.all(16.h), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Row( children: [ Utils.buildSvgWithAssets(icon: AppAssets.ask_doctor_icon, width: 24.w, height: 24.h, iconColor: AppColors.greyTextColor), SizedBox(width: 12.w), Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ LocaleKeys.feedbackType.tr().toText16(color: AppColors.textColor, weight: FontWeight.w500), (getIt.get().isArabic() ? contactUsViewModel.selectedFeedbackType.nameAR : contactUsViewModel.selectedFeedbackType.nameEN) .toText14(color: AppColors.greyTextColor, weight: FontWeight.w500), ], ), ], ), Utils.buildSvgWithAssets(icon: AppAssets.arrow_down, width: 25.h, height: 25.h), ], ).onPress(() { showCommonBottomSheetWithoutHeight(context, title: "Select Feedback Type".needTranslation, child: Container( width: double.infinity, decoration: RoundedRectangleBorder().toSmoothCornerDecoration(color: AppColors.whiteColor, borderRadius: 24), child: ListView.builder( itemCount: contactUsViewModel.feedbackTypeList.length, physics: NeverScrollableScrollPhysics(), padding: EdgeInsets.only(top: 8, bottom: 8), shrinkWrap: true, itemBuilder: (innerContext, index) { return Theme( data: Theme.of(context).copyWith( listTileTheme: ListTileThemeData(horizontalTitleGap: 4), ), child: RadioListTile( title: Text( getIt.get().isArabic() ? contactUsViewModel.feedbackTypeList[index].nameAR : contactUsViewModel.feedbackTypeList[index].nameEN, style: TextStyle( fontSize: 16.h, fontWeight: FontWeight.w500, ), ), value: contactUsViewModel.feedbackTypeList[index], fillColor: WidgetStateProperty.resolveWith((states) { if (states.contains(WidgetState.selected)) { return AppColors.primaryRedColor; } return Color(0xffEEEEEE); }), contentPadding: EdgeInsets.only(left: 12.h, right: 12.h), groupValue: contactUsViewModel.selectedFeedbackType, onChanged: (FeedbackType? newValue) async { Navigator.pop(context); contactUsViewModel.setSelectedFeedbackType(newValue!); if (contactUsViewModel.selectedFeedbackType.id == 1) { LoaderBottomSheet.showLoader(loadingText: "Loading appointments list...".needTranslation); await medicalFileViewModel.getPatientMedicalReportAppointmentsList(onSuccess: (val) async { LoaderBottomSheet.hideLoader(); bool? value = await Navigator.of(context).push( CustomPageRoute( page: FeedbackAppointmentSelection(), fullScreenDialog: true, direction: AxisDirection.down, ), ); if (value != null) { // showConfirmRequestMedicalReportBottomSheet(); } }, onError: (err) { LoaderBottomSheet.hideLoader(); showCommonBottomSheetWithoutHeight( context, child: Utils.getErrorWidget(loadingText: "You do not have any appointments to submit a feedback.".needTranslation), callBackFunc: () {}, isFullScreen: false, isCloseButtonVisible: true, ); }); } else { contactUsViewModel.setPatientFeedbackSelectedAppointment(null); } }, ), ); }, ), ), callBackFunc: () {}, isFullScreen: false, isCloseButtonVisible: true); }), ]), ), ), if (contactUsViewModel.patientFeedbackSelectedAppointment != null) ...[ SizedBox(height: 16.h), "Selected Appointment:".needTranslation.toText16(isBold: true), SizedBox(height: 8.h), Container( decoration: RoundedRectangleBorder().toSmoothCornerDecoration( color: AppColors.whiteColor, borderRadius: 20.r, hasShadow: false, ), padding: EdgeInsets.all(16.h), child: Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ Image.network( contactUsViewModel.patientFeedbackSelectedAppointment!.doctorImageURL!, width: 63.h, height: 63.h, fit: BoxFit.cover, ).circle(100).toShimmer2(isShow: false), SizedBox(width: 16.h), Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ (contactUsViewModel.patientFeedbackSelectedAppointment!.doctorNameObj!).toText16(isBold: true, maxlines: 1).toShimmer2(isShow: false), SizedBox(height: 8.h), Wrap( direction: Axis.horizontal, spacing: 3.h, runSpacing: 4.h, children: [ AppCustomChipWidget(labelText: contactUsViewModel.patientFeedbackSelectedAppointment!.clinicName!).toShimmer2(isShow: false), AppCustomChipWidget(labelText: contactUsViewModel.patientFeedbackSelectedAppointment!.projectName!).toShimmer2(isShow: false), AppCustomChipWidget( icon: AppAssets.appointment_calendar_icon, labelText: DateUtil.formatDateToDate(DateUtil.convertStringToDate(contactUsViewModel.patientFeedbackSelectedAppointment!.appointmentDate), false), ).toShimmer2(isShow: false), ], ), ], ), ), ], ), ), ], SizedBox(height: 16.h), TextInputWidget( labelText: "Subject".needTranslation, hintText: "Enter subject here".needTranslation, controller: subjectTextController, isEnable: true, prefix: null, autoFocus: false, isBorderAllowed: false, keyboardType: TextInputType.text, padding: EdgeInsets.symmetric( vertical: ResponsiveExtension(10).h, horizontal: ResponsiveExtension(15).h, ), ), SizedBox(height: 16.h), TextInputWidget( labelText: "Message".needTranslation, hintText: "Enter message here".needTranslation, controller: messageTextController, isEnable: true, prefix: null, autoFocus: false, isBorderAllowed: false, isMultiline: true, keyboardType: TextInputType.text, padding: EdgeInsets.symmetric( vertical: ResponsiveExtension(10).h, horizontal: ResponsiveExtension(15).h, ), ), SizedBox(height: 16.h), CustomButton( text: LocaleKeys.selectAttachment.tr(context: context), onPressed: () async { ImageOptions.showImageOptionsNew( context, true, (String image, file) { print(image); print(file); Navigator.pop(context); contactUsViewModel.addFeedbackAttachment(image); }, ); }, backgroundColor: AppColors.secondaryLightRedColor, borderColor: AppColors.secondaryLightRedColor, textColor: AppColors.primaryRedColor, fontSize: 14.f, fontWeight: FontWeight.w500, borderRadius: 10.r, padding: EdgeInsets.symmetric(horizontal: 10.w), height: 40.h, icon: AppAssets.file_icon, iconColor: AppColors.primaryRedColor, iconSize: 16.h, ), SizedBox(height: 16.h), contactUsViewModel.feedbackAttachmentList.isNotEmpty ? Container( decoration: RoundedRectangleBorder().toSmoothCornerDecoration( color: AppColors.whiteColor, borderRadius: 12.r, hasShadow: false, ), child: ListView.builder( padding: EdgeInsets.all(16.h), shrinkWrap: true, itemCount: contactUsViewModel.feedbackAttachmentList.length, itemBuilder: (BuildContext context, int 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), ], ), Utils.buildSvgWithAssets(icon: AppAssets.cancel_circle_icon).onPress(() { contactUsViewModel.removeFeedbackAttachment(contactUsViewModel.feedbackAttachmentList[index]); }), ], ); }, ), ) : SizedBox.shrink(), ], ); } else { return Container(); } } }