diff --git a/.gitignore b/.gitignore index 3ada50c..79c113f 100644 --- a/.gitignore +++ b/.gitignore @@ -43,4 +43,3 @@ app.*.map.json /android/app/debug /android/app/profile /android/app/release -/android/ diff --git a/lib/features/lab/lab_view_model.dart b/lib/features/lab/lab_view_model.dart index 115b28d..94ddd87 100644 --- a/lib/features/lab/lab_view_model.dart +++ b/lib/features/lab/lab_view_model.dart @@ -12,9 +12,9 @@ class LabViewModel extends ChangeNotifier { List patientLabOrders = []; - List labSuggestionsList =[]; + late List _labSuggestionsList = []; - get labSuggestions => labSuggestionsList; + List get labSuggestions => _labSuggestionsList; LabViewModel({required this.labRepo, required this.errorHandlerService}); @@ -38,6 +38,7 @@ class LabViewModel extends ChangeNotifier { patientLabOrders = apiResponse.data!; isLabOrdersLoading = false; isLabResultsLoading = false; + filterSuggestions(); notifyListeners(); if (onSuccess != null) { onSuccess(apiResponse); @@ -48,6 +49,13 @@ class LabViewModel extends ChangeNotifier { } filterSuggestions(){ + final List labels = patientLabOrders + .expand((order) => order.testDetails!) // flatten testDetails + .map((detail) => detail.description) // pick description + .whereType() // remove nulls if any + .toList(); + _labSuggestionsList = labels.toSet().toList(); // remove duplicates by converting to a set and back to a list + notifyListeners(); } } diff --git a/lib/presentation/lab/lab_orders_page.dart b/lib/presentation/lab/lab_orders_page.dart index e829c93..1581ac3 100644 --- a/lib/presentation/lab/lab_orders_page.dart +++ b/lib/presentation/lab/lab_orders_page.dart @@ -5,7 +5,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_staggered_animations/flutter_staggered_animations.dart'; import 'package:hmg_patient_app_new/core/app_assets.dart'; import 'package:hmg_patient_app_new/core/utils/date_util.dart'; -import 'package:hmg_patient_app_new/core/utils/size_config.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'; @@ -15,7 +14,6 @@ import 'package:hmg_patient_app_new/generated/locale_keys.g.dart'; import 'package:hmg_patient_app_new/features/lab/lab_view_model.dart'; import 'package:hmg_patient_app_new/presentation/lab/search_lab_report.dart'; import 'package:hmg_patient_app_new/theme/colors.dart'; -import 'package:hmg_patient_app_new/widgets/bottom_sheet.dart'; import 'package:hmg_patient_app_new/widgets/buttons/custom_button.dart'; import 'package:hmg_patient_app_new/widgets/common_bottom_sheet.dart'; import 'package:hmg_patient_app_new/widgets/shimmer/movies_shimmer_widget.dart'; @@ -65,9 +63,9 @@ class _LabOrdersPageState extends State { Utils.buildSvgWithAssets(icon: AppAssets.search_icon).onPress(() { if(model.isLabOrdersLoading){ return; - } else { - labSuggestions = getLabSuggestions(model); - showCommonBottomSheet(context, child: SearchLabResultsContent(), + }else { + + showCommonBottomSheet(context, child: SearchLabResultsContent(labSuggestionsList: model.labSuggestions), callBackFunc: () {}, title: LocaleKeys.searchLabReport.tr(), height: ResponsiveExtension.screenHeight, diff --git a/lib/presentation/lab/search_lab_report.dart b/lib/presentation/lab/search_lab_report.dart index 1c05174..d513b35 100644 --- a/lib/presentation/lab/search_lab_report.dart +++ b/lib/presentation/lab/search_lab_report.dart @@ -9,25 +9,54 @@ import 'package:hmg_patient_app_new/widgets/buttons/custom_button.dart'; import 'package:hmg_patient_app_new/widgets/input_widget.dart'; import 'package:sizer/sizer.dart'; -class SearchLabResultsContent extends StatelessWidget { - const SearchLabResultsContent({super.key}); +class SearchLabResultsContent extends StatefulWidget { + final List labSuggestionsList; - final List _chipLabels = const [ - "Blood Test", - "X-Ray", - "MRI Scan", - "CT Scan", - "Ultrasound", - "Urine Test", - "Allergy Test", - "Cholesterol Test", - "Diabetes Test", - "Thyroid Test", - ]; + const SearchLabResultsContent({super.key, required this.labSuggestionsList}); @override - Widget build(BuildContext context) { + State createState() => _SearchLabResultsContentState(); +} + +class _SearchLabResultsContentState extends State { + TextEditingController searchEditingController = TextEditingController(); + List filteredSuggestions = []; + + @override + void initState() { + super.initState(); + filteredSuggestions = List.from(widget.labSuggestionsList); + + // Listen for changes in the search field + searchEditingController.addListener(() { + filterSuggestions(); + }); + } + + @override + void dispose() { + searchEditingController.dispose(); + super.dispose(); + } + + void filterSuggestions() { + final query = searchEditingController.text.toLowerCase(); + if (query.isEmpty) { + setState(() { + filteredSuggestions = List.from(widget.labSuggestionsList); + }); + } else { + setState(() { + filteredSuggestions = widget.labSuggestionsList + .where((suggestion) => suggestion.toLowerCase().contains(query)) + .toList(); + }); + } + } + + @override + Widget build(BuildContext context) { return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -37,19 +66,23 @@ class SearchLabResultsContent extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.start, children: [ TextInputWidget( - labelText:"Search lab results", + labelText: "Search lab results", hintText: "Type test name", - controller: TextEditingController(), + controller: searchEditingController, isEnable: true, prefix: null, autoFocus: true, isBorderAllowed: false, - padding: EdgeInsets.symmetric(vertical:ResponsiveExtension(10).h, horizontal: ResponsiveExtension(15).h), - + padding: EdgeInsets.symmetric( + vertical: ResponsiveExtension(10).h, + horizontal: ResponsiveExtension(15).h, + ), ), - SizedBox(height: ResponsiveExtension(20).h), - "Suggestions".toText16(isBold: true), - const SizedBox(height: 12), + SizedBox(height: ResponsiveExtension(20).h), + if (filteredSuggestions.isNotEmpty) ...[ + "Suggestions".toText16(isBold: true), + const SizedBox(height: 12), + ], ], ), ), @@ -60,11 +93,13 @@ class SearchLabResultsContent extends StatelessWidget { alignment: WrapAlignment.start, spacing: 10, runSpacing: 10, - children: _chipLabels + children: filteredSuggestions .map((label) => SuggestionChip( - label: label, - onTap: () {}, - )) + label: label, + onTap: () { + searchEditingController.text = label; + }, + )) .toList(), ), ), @@ -76,7 +111,7 @@ class SearchLabResultsContent extends StatelessWidget { text: LocaleKeys.search.tr(), icon: AppAssets.search_icon, iconColor: Colors.white, - onPressed: () => Navigator.pop(context), + onPressed: () => Navigator.pop(context, searchEditingController.text), ), ), ], @@ -99,12 +134,16 @@ class SuggestionChip extends StatelessWidget { @override Widget build(BuildContext context) { return GestureDetector( - onTap: onTap, // optional tap callback + onTap: onTap, child: Container( padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 8), decoration: BoxDecoration( color: isSelected ? AppColors.primaryRedColor : AppColors.whiteColor, borderRadius: BorderRadius.circular(8), + border: Border.all( + color: AppColors.greyColor, + width: 1, + ), ), child: label.toText12( color: isSelected ? Colors.white : Colors.black87, @@ -113,4 +152,4 @@ class SuggestionChip extends StatelessWidget { ), ); } -} +} \ No newline at end of file diff --git a/pubspec.lock b/pubspec.lock index e2ebb3b..c503e1b 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -29,10 +29,10 @@ packages: dependency: transitive description: name: async - sha256: "758e6d74e971c3e5aceb4110bfd6698efc7f501675bcfe0c775459a8140750eb" + sha256: d2872f9c19731c2e5f10444b14686eb7cc85c76274bd6c16e1816bff9a3bab63 url: "https://pub.dev" source: hosted - version: "2.13.0" + version: "2.12.0" audio_session: dependency: transitive description: @@ -742,14 +742,6 @@ packages: url: "https://pub.dev" source: hosted version: "13.1.3" - hijri_gregorian_calendar: - dependency: "direct main" - description: - name: hijri_gregorian_calendar - sha256: "9d23b52192783c1ad134b1ac001be7977342cb579c6b380647b6494fbd464d29" - url: "https://pub.dev" - source: hosted - version: "0.0.4" html: dependency: transitive description: @@ -1599,10 +1591,10 @@ packages: dependency: transitive description: name: vm_service - sha256: ddfa8d30d89985b96407efce8acbdd124701f96741f2d981ca860662f1c0dc02 + sha256: "0968250880a6c5fe7edc067ed0a13d4bae1577fe2771dcf3010d52c4a9d3ca14" url: "https://pub.dev" source: hosted - version: "15.0.0" + version: "14.3.1" web: dependency: "direct main" description: @@ -1644,5 +1636,5 @@ packages: source: hosted version: "6.5.0" sdks: - dart: ">=3.8.1 <4.0.0" + dart: ">=3.8.0-0 <4.0.0" flutter: ">=3.29.0" diff --git a/pubspec.yaml b/pubspec.yaml index 829970a..0f02a05 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -69,7 +69,6 @@ dependencies: web: any flutter_staggered_animations: ^1.1.1 smooth_corner: ^1.1.1 - hijri_gregorian_calendar: ^0.0.4 dev_dependencies: flutter_test: @@ -83,7 +82,6 @@ flutter: - assets/ - assets/fonts/ - assets/langs/ - - assets/json/ - assets/images/ - assets/images/svg/ - assets/images/png/