lab search added

pull/10/head
Sultan khan 2 months ago
parent 2f2a8f3f8f
commit 29aae34726

@ -12,9 +12,9 @@ class LabViewModel extends ChangeNotifier {
List<PatientLabOrdersResponseModel> patientLabOrders = [];
List<String> labSuggestionsList =[];
late List<String> _labSuggestionsList = [];
get labSuggestions => labSuggestionsList;
List<String> 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<String> labels = patientLabOrders
.expand((order) => order.testDetails!) // flatten testDetails
.map((detail) => detail.description) // pick description
.whereType<String>() // remove nulls if any
.toList();
_labSuggestionsList = labels.toSet().toList(); // remove duplicates by converting to a set and back to a list
notifyListeners();
}
}

@ -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';
@ -66,8 +64,8 @@ class _LabOrdersPageState extends State<LabOrdersPage> {
if(model.isLabOrdersLoading){
return;
}else {
labSuggestions = getLabSuggestions(model);
showCommonBottomSheet(context, child: SearchLabResultsContent(),
showCommonBottomSheet(context, child: SearchLabResultsContent(labSuggestionsList: model.labSuggestions),
callBackFunc: () {},
title: LocaleKeys.searchLabReport.tr(),
height: ResponsiveExtension.screenHeight,
@ -277,13 +275,6 @@ class _LabOrdersPageState extends State<LabOrdersPage> {
return "";
}
}
getLabSuggestions(LabViewModel model) {
if(model.patientLabOrders.isEmpty){
return [];
}
return model.patientLabOrders.map((m) => m.testDetails).toList();
}
}

@ -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<String> labSuggestionsList;
final List<String> _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<SearchLabResultsContent> createState() => _SearchLabResultsContentState();
}
class _SearchLabResultsContentState extends State<SearchLabResultsContent> {
TextEditingController searchEditingController = TextEditingController();
List<String> 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 {
),
);
}
}
}
Loading…
Cancel
Save