Patient Manager search function fixed to display only matches
This commit is contained in:
@@ -15,18 +15,17 @@ class BuildPatientsList extends StatefulWidget {
|
|||||||
State<BuildPatientsList> createState() => _BuildPatientsListState();
|
State<BuildPatientsList> createState() => _BuildPatientsListState();
|
||||||
}
|
}
|
||||||
|
|
||||||
int indexOn = 0;
|
|
||||||
|
|
||||||
class _BuildPatientsListState extends State<BuildPatientsList> {
|
class _BuildPatientsListState extends State<BuildPatientsList> {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return ListView.separated(
|
return ListView.separated(
|
||||||
separatorBuilder: (BuildContext context, int index) {
|
separatorBuilder: (BuildContext context, index) {
|
||||||
return const Divider();
|
return const Divider();
|
||||||
},
|
},
|
||||||
itemCount: widget.patients.length,
|
itemCount: widget.patients.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
//final patient = widget.patients[index].id_no.contains(widget.searchString);
|
//final patient = widget.patients[index].id_no.contains(widget.searchString);
|
||||||
|
//print(index);
|
||||||
return widget.patients[index].id_no.contains(widget.searchString)
|
return widget.patients[index].id_no.contains(widget.searchString)
|
||||||
? ListTile(
|
? ListTile(
|
||||||
title: Text(
|
title: Text(
|
||||||
@@ -40,7 +39,7 @@ class _BuildPatientsListState extends State<BuildPatientsList> {
|
|||||||
},
|
},
|
||||||
trailing: const Icon(Icons.arrow_forward),
|
trailing: const Icon(Icons.arrow_forward),
|
||||||
)
|
)
|
||||||
: Container();
|
: null;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ class _PatientManagerState extends State<PatientManager> {
|
|||||||
TextEditingController searchController = TextEditingController();
|
TextEditingController searchController = TextEditingController();
|
||||||
String endpoint = "http://localhost:80/patients/user/";
|
String endpoint = "http://localhost:80/patients/user/";
|
||||||
late Future<List<Patient>> futurePatients;
|
late Future<List<Patient>> futurePatients;
|
||||||
|
// late Widget displayWidget;
|
||||||
|
//List<Patient> tempList;
|
||||||
String searchString = "";
|
String searchString = "";
|
||||||
|
|
||||||
Future<List<Patient>> fetchPatients(String endpoint) async {
|
Future<List<Patient>> fetchPatients(String endpoint) async {
|
||||||
@@ -41,9 +43,32 @@ class _PatientManagerState extends State<PatientManager> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<Patient> filterSearchResults(List<Patient> mainList, String query) {
|
||||||
|
return mainList
|
||||||
|
.where((tempList) => tempList.id_no.contains(query.toLowerCase()))
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Widget displayList(List<Patient> patientsList, String searchString) {
|
||||||
|
// if (searchString.isNotEmpty && searchString != "") {
|
||||||
|
// return BuildPatientsList(
|
||||||
|
// patients: patientsList,
|
||||||
|
// searchString: searchString,
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
// return const Center(
|
||||||
|
// child: Text(
|
||||||
|
// "Please search for a Patient.",
|
||||||
|
// style: TextStyle(fontSize: 25, color: Colors.grey),
|
||||||
|
// textAlign: TextAlign.center,
|
||||||
|
// ),
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
futurePatients = fetchPatients(endpoint + widget.userEmail);
|
futurePatients = fetchPatients(endpoint + widget.userEmail);
|
||||||
|
//displayWidget = displayList(tempList, searchString);
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,48 +96,57 @@ class _PatientManagerState extends State<PatientManager> {
|
|||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
body: FutureBuilder(
|
body: Row(
|
||||||
future: futurePatients,
|
children: [
|
||||||
builder: (context, snapshot) {
|
Expanded(
|
||||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
child: Column(children: [
|
||||||
return const Center(child: CircularProgressIndicator());
|
//spacer
|
||||||
} else if (snapshot.hasData) {
|
const SizedBox(height: 10),
|
||||||
final patientsList = snapshot.data!;
|
MySearchField(
|
||||||
|
controller: searchController,
|
||||||
|
hintText: "ID Search",
|
||||||
|
required: false,
|
||||||
|
editable: true,
|
||||||
|
onTap: () {},
|
||||||
|
onChanged: (value) {
|
||||||
|
setState(() {
|
||||||
|
searchString = value;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
//spacer
|
||||||
|
const SizedBox(height: 10),
|
||||||
|
//Expanded(child: displayWidget),
|
||||||
|
FutureBuilder(
|
||||||
|
future: futurePatients,
|
||||||
|
builder: (context, snapshot) {
|
||||||
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||||
|
return const Center(child: CircularProgressIndicator());
|
||||||
|
} else if (snapshot.hasData) {
|
||||||
|
List<Patient> patientsList;
|
||||||
|
//print(patientsList);
|
||||||
|
if (searchString == "") {
|
||||||
|
patientsList = snapshot.data!;
|
||||||
|
} else {
|
||||||
|
patientsList =
|
||||||
|
filterSearchResults(snapshot.data!, searchString);
|
||||||
|
}
|
||||||
|
|
||||||
return Row(
|
return Expanded(
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: Column(children: [
|
|
||||||
//spacer
|
|
||||||
const SizedBox(height: 10),
|
|
||||||
MySearchField(
|
|
||||||
controller: searchController,
|
|
||||||
hintText: "ID Search",
|
|
||||||
required: false,
|
|
||||||
editable: true,
|
|
||||||
onTap: () {},
|
|
||||||
onChanged: (value) {
|
|
||||||
setState(() {
|
|
||||||
searchString = value;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
//spacer
|
|
||||||
const SizedBox(height: 10),
|
|
||||||
Expanded(
|
|
||||||
child: BuildPatientsList(
|
child: BuildPatientsList(
|
||||||
patients: patientsList,
|
patients: patientsList,
|
||||||
searchString: searchString,
|
searchString: searchString,
|
||||||
),
|
),
|
||||||
),
|
);
|
||||||
]),
|
} else {
|
||||||
),
|
return const PatManAppDrawer(
|
||||||
],
|
userEmail: "Error pulling email");
|
||||||
);
|
}
|
||||||
} else {
|
},
|
||||||
return const PatManAppDrawer(userEmail: "Error pulling email");
|
),
|
||||||
}
|
]),
|
||||||
},
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user