From c11e859df16765fb2b80f60c434714074ba2606b Mon Sep 17 00:00:00 2001 From: aamir-csol Date: Mon, 12 Jan 2026 11:40:08 +0300 Subject: [PATCH] search doctor by name filter. --- .../book_appointments_view_model.dart | 21 ++++ .../search_doctor_by_name.dart | 109 ++++++++++++------ 2 files changed, 92 insertions(+), 38 deletions(-) diff --git a/lib/features/book_appointments/book_appointments_view_model.dart b/lib/features/book_appointments/book_appointments_view_model.dart index 380d2db..aa1467b 100644 --- a/lib/features/book_appointments/book_appointments_view_model.dart +++ b/lib/features/book_appointments/book_appointments_view_model.dart @@ -165,6 +165,27 @@ class BookAppointmentsViewModel extends ChangeNotifier { notifyListeners(); } + // Sort filtered doctor list by clinic or hospital + void sortFilteredDoctorList(bool sortByClinic) { + isSortByClinic = sortByClinic; + if (sortByClinic) { + // Sort by clinic name + filteredDoctorList.sort((a, b) { + final clinicA = (a.clinicName ?? 'Unknown').toLowerCase(); + final clinicB = (b.clinicName ?? 'Unknown').toLowerCase(); + return clinicA.compareTo(clinicB); + }); + } else { + // Sort by hospital/project name + filteredDoctorList.sort((a, b) { + final hospitalA = (a.projectName ?? 'Unknown').toLowerCase(); + final hospitalB = (b.projectName ?? 'Unknown').toLowerCase(); + return hospitalA.compareTo(hospitalB); + }); + } + notifyListeners(); + } + // Group doctors by clinic and hospital void _groupDoctorsList() { final clinicMap = >{}; diff --git a/lib/presentation/book_appointment/search_doctor_by_name.dart b/lib/presentation/book_appointment/search_doctor_by_name.dart index d008497..559e1e5 100644 --- a/lib/presentation/book_appointment/search_doctor_by_name.dart +++ b/lib/presentation/book_appointment/search_doctor_by_name.dart @@ -43,7 +43,7 @@ class _SearchDoctorByNameState extends State { body: Column( children: [ Expanded( - child: CollapsingListView( + child: CollapsingListView( title: "Choose Doctor".needTranslation, child: SingleChildScrollView( child: Padding( @@ -76,7 +76,7 @@ class _SearchDoctorByNameState extends State { ) : null, onChange: (value) { - // bookAppointmentsViewModel.filterClinics(value!); + // bookAppointmentsViewModel.filterClinics(value!); }, padding: EdgeInsets.symmetric( vertical: ResponsiveExtension(10).h, @@ -89,43 +89,41 @@ class _SearchDoctorByNameState extends State { child: SizedBox( height: 56.h, width: 56.h, - child: DecoratedBox(decoration: RoundedRectangleBorder().toSmoothCornerDecoration( - color: AppColors.whiteColor, - borderRadius: 10.h, - hasShadow: false, - ), - child: Utils.buildSvgWithAssets(icon: AppAssets.ic_filters, - height: 24.h, - width: 24.h, ).paddingAll(16.h).onPress((){ - context.read() + child: DecoratedBox( + decoration: RoundedRectangleBorder().toSmoothCornerDecoration( + color: AppColors.whiteColor, + borderRadius: 10.h, + hasShadow: false, + ), + child: Utils.buildSvgWithAssets( + icon: AppAssets.ic_filters, + height: 24.h, + width: 24.h, + ).paddingAll(16.h).onPress(() { + context.read() ..clearSelection() - ..clearSearchFilters() - ..getFiltersFromDoctorList( - bookAppointmentsViewModel.doctorsList - )..setSelections( - bookAppointmentsViewModel.selectedFacilityForFilters?.toList(), - bookAppointmentsViewModel.selectedRegionForFilters?.toList(), - bookAppointmentsViewModel.selectedClinicForFilters, - bookAppointmentsViewModel.selectedHospitalForFilters, - bookAppointmentsViewModel.applyFilters) ; - Navigator.of(context).push( - PageRouteBuilder( - pageBuilder: (context, animation, secondaryAnimation) => DoctorsFilters(), // Replace YourNewPage with your actual page widget - transitionsBuilder: (context, animation, secondaryAnimation, child) { - const begin = Offset(0.0, 1.0); // Start from the bottom (y=1.0) - const end = Offset.zero; // End at the original position (y=0.0) - final tween = Tween(begin: begin, end: end); - final offsetAnimation = animation.drive(tween); + ..clearSearchFilters() + ..getFiltersFromDoctorList(bookAppointmentsViewModel.doctorsList) + ..setSelections(bookAppointmentsViewModel.selectedFacilityForFilters?.toList(), bookAppointmentsViewModel.selectedRegionForFilters?.toList(), + bookAppointmentsViewModel.selectedClinicForFilters, bookAppointmentsViewModel.selectedHospitalForFilters, bookAppointmentsViewModel.applyFilters); + Navigator.of(context).push( + PageRouteBuilder( + pageBuilder: (context, animation, secondaryAnimation) => DoctorsFilters(), // Replace YourNewPage with your actual page widget + transitionsBuilder: (context, animation, secondaryAnimation, child) { + const begin = Offset(0.0, 1.0); // Start from the bottom (y=1.0) + const end = Offset.zero; // End at the original position (y=0.0) + final tween = Tween(begin: begin, end: end); + final offsetAnimation = animation.drive(tween); - return SlideTransition( - position: offsetAnimation, - child: child, - ); - }, - transitionDuration: Duration(milliseconds: 200), // Adjust duration as needed - ), - ); - }), + return SlideTransition( + position: offsetAnimation, + child: child, + ); + }, + transitionDuration: Duration(milliseconds: 200), // Adjust duration as needed + ), + ); + }), ), ), ) @@ -136,9 +134,43 @@ class _SearchDoctorByNameState extends State { return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ + if (bookAppointmentsVM.isDoctorSearchByNameStarted) + Row( + children: [ + CustomButton( + text: LocaleKeys.byClinic.tr(context: context), + onPressed: () { + bookAppointmentsVM.sortFilteredDoctorList(true); + }, + backgroundColor: bookAppointmentsVM.isSortByClinic ? AppColors.bgRedLightColor : AppColors.whiteColor, + borderColor: bookAppointmentsVM.isSortByClinic ? AppColors.primaryRedColor : AppColors.textColor.withOpacity(0.2), + textColor: bookAppointmentsVM.isSortByClinic ? AppColors.primaryRedColor : AppColors.blackColor, + fontSize: 12, + fontWeight: FontWeight.w500, + borderRadius: 10, + padding: EdgeInsets.fromLTRB(10, 0, 10, 0), + height: 40.h, + ), + SizedBox(width: 8.h), + CustomButton( + text: LocaleKeys.byHospital.tr(context: context), + onPressed: () { + bookAppointmentsVM.sortFilteredDoctorList(false); + }, + backgroundColor: bookAppointmentsVM.isSortByClinic ? AppColors.whiteColor : AppColors.bgRedLightColor, + borderColor: bookAppointmentsVM.isSortByClinic ? AppColors.textColor.withOpacity(0.2) : AppColors.primaryRedColor, + textColor: bookAppointmentsVM.isSortByClinic ? AppColors.blackColor : AppColors.primaryRedColor, + fontSize: 12, + fontWeight: FontWeight.w500, + borderRadius: 10, + padding: EdgeInsets.fromLTRB(10, 0, 10, 0), + height: 40.h, + ), + ], + ).paddingSymmetrical(0.h, 0.h), bookAppointmentsVM.isDoctorSearchByNameStarted ? ListView.separated( - padding: EdgeInsets.only(top: 24.h), + padding: EdgeInsets.only(top: 20.h), shrinkWrap: true, physics: NeverScrollableScrollPhysics(), itemCount: bookAppointmentsVM.isDoctorsListLoading ? 5 : bookAppointmentsVM.filteredDoctorList.length, @@ -261,6 +293,7 @@ class _SearchDoctorByNameState extends State { ), ); } + @override void dispose() { bookAppointmentsViewModel.doctorsList.clear();