Enable search function on patient manager
This commit is contained in:
@@ -3,9 +3,11 @@ import 'package:patient_manager/objects/patients.dart';
|
|||||||
|
|
||||||
class BuildPatientsList extends StatefulWidget {
|
class BuildPatientsList extends StatefulWidget {
|
||||||
final List<Patient> patients;
|
final List<Patient> patients;
|
||||||
|
final searchString;
|
||||||
const BuildPatientsList({
|
const BuildPatientsList({
|
||||||
super.key,
|
super.key,
|
||||||
required this.patients,
|
required this.patients,
|
||||||
|
required this.searchString,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -18,11 +20,15 @@ class _BuildPatientsListState extends State<BuildPatientsList> {
|
|||||||
return ListView.builder(
|
return ListView.builder(
|
||||||
itemCount: widget.patients.length,
|
itemCount: widget.patients.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
final patient = widget.patients[index];
|
//final patient = widget.patients[index].id_no.contains(widget.searchString);
|
||||||
return ListTile(
|
return widget.patients[index].id_no.contains(widget.searchString)
|
||||||
title: Text(patient.first_name + " " + patient.last_name),
|
? ListTile(
|
||||||
subtitle: Text(patient.id_no),
|
title: Text(widget.patients[index].first_name +
|
||||||
);
|
" " +
|
||||||
|
widget.patients[index].last_name),
|
||||||
|
subtitle: Text(widget.patients[index].id_no),
|
||||||
|
)
|
||||||
|
: Container();
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
42
Frontend/patient_manager/lib/components/mySearchInput.dart
Normal file
42
Frontend/patient_manager/lib/components/mySearchInput.dart
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class MySearchField extends StatelessWidget {
|
||||||
|
final controller;
|
||||||
|
final String hintText;
|
||||||
|
final void Function(String)? onChanged;
|
||||||
|
|
||||||
|
const MySearchField({
|
||||||
|
super.key,
|
||||||
|
required this.controller,
|
||||||
|
required this.hintText,
|
||||||
|
required this.onChanged,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 25.0),
|
||||||
|
child: TextField(
|
||||||
|
onChanged: onChanged,
|
||||||
|
controller: controller,
|
||||||
|
obscureText: false,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
fillColor: Colors.white,
|
||||||
|
prefixIcon: const Icon(Icons.search),
|
||||||
|
filled: true,
|
||||||
|
hintText: hintText,
|
||||||
|
hintStyle: TextStyle(color: Colors.blueGrey[400]),
|
||||||
|
enabledBorder: const OutlineInputBorder(
|
||||||
|
borderSide: BorderSide(
|
||||||
|
color: Colors.blueAccent,
|
||||||
|
width: 2.0,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
focusedBorder: const OutlineInputBorder(
|
||||||
|
borderSide: BorderSide(color: Colors.blue),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,24 +5,17 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:patient_manager/components/buildPatientList.dart';
|
import 'package:patient_manager/components/buildPatientList.dart';
|
||||||
import 'package:patient_manager/components/myAppBar.dart';
|
import 'package:patient_manager/components/myAppBar.dart';
|
||||||
import 'package:patient_manager/components/myAppDrawer.dart';
|
import 'package:patient_manager/components/myAppDrawer.dart';
|
||||||
import 'package:patient_manager/main.dart';
|
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
import 'package:mysql_client/mysql_client.dart';
|
import 'package:mysql_client/mysql_client.dart';
|
||||||
|
import 'package:patient_manager/components/mySearchInput.dart';
|
||||||
import 'package:patient_manager/objects/patients.dart';
|
import 'package:patient_manager/objects/patients.dart';
|
||||||
|
|
||||||
Future<List<Patient>> fetchPatients(String endpoint) async {
|
Future<List<Patient>> fetchPatients(String endpoint) async {
|
||||||
print("fetch patients");
|
|
||||||
final response = await http.get(Uri.parse(endpoint));
|
final response = await http.get(Uri.parse(endpoint));
|
||||||
//print("Status Code: " + response.statusCode.toString());
|
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
Iterable l = jsonDecode(response.body);
|
Iterable l = jsonDecode(response.body);
|
||||||
List<Patient> patients =
|
List<Patient> patients =
|
||||||
List<Patient>.from(l.map((model) => Patient.fromJson(model)));
|
List<Patient>.from(l.map((model) => Patient.fromJson(model)));
|
||||||
print("convert response to json");
|
|
||||||
//print(response.body);
|
|
||||||
// final patientsData =
|
|
||||||
// Patient.fromJson(jsonDecode(response.body)[0] as Map<String, dynamic>);
|
|
||||||
print(patients);
|
|
||||||
return patients;
|
return patients;
|
||||||
} else {
|
} else {
|
||||||
throw Exception('failed to load patients');
|
throw Exception('failed to load patients');
|
||||||
@@ -42,36 +35,25 @@ class PatientManager extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _PatientManagerState extends State<PatientManager> {
|
class _PatientManagerState extends State<PatientManager> {
|
||||||
//String useremail = "";
|
TextEditingController searchController = TextEditingController();
|
||||||
String endpoint = "http://localhost:80/patients/user/";
|
String endpoint = "http://localhost:80/patients/user/";
|
||||||
late MySQLConnection conn;
|
late MySQLConnection conn;
|
||||||
String resultsofDB = "";
|
String resultsofDB = "";
|
||||||
late Future<List<Patient>> futurePatients;
|
late Future<List<Patient>> futurePatients;
|
||||||
|
String searchString = "";
|
||||||
|
|
||||||
// Future<String> getuserEmail() async {
|
@override
|
||||||
// final res = await client.auth.getUser();
|
void initState() {
|
||||||
// //final response = await http.get(Uri.parse(endpoint));
|
futurePatients = fetchPatients(endpoint + widget.userEmail);
|
||||||
// //print(json.decode(response.body));
|
super.initState();
|
||||||
// if (res.user!.email != null) {
|
}
|
||||||
// //print("User: " + res.user!.email.toString());
|
|
||||||
// useremail = res.user!.email!;
|
|
||||||
|
|
||||||
// //print(useremail);
|
// void filterSearchResults(String query) {
|
||||||
// return useremail;
|
// setState(() {
|
||||||
// }
|
// futurePatients = futurePatientsList
|
||||||
// return "";
|
// .where((item) => item.toLowerCase().contains(query.toLowerCase()))
|
||||||
// }
|
// .toList();
|
||||||
|
// });
|
||||||
// @override
|
|
||||||
// void initState() {
|
|
||||||
// // String endpoint = "http://localhost:80/patients/";
|
|
||||||
// print("init now");
|
|
||||||
// print("Endpoint 1: " + endpoint);
|
|
||||||
// //print(getuserEmail());
|
|
||||||
// endpoint += userEmail;
|
|
||||||
// print("Endpoint 1: " + endpoint);
|
|
||||||
// futurePatients = fetchPatients(endpoint);
|
|
||||||
// super.initState();
|
|
||||||
// }
|
// }
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -80,38 +62,39 @@ class _PatientManagerState extends State<PatientManager> {
|
|||||||
appBar: const MyAppBar(barTitle: "Patient Manager"),
|
appBar: const MyAppBar(barTitle: "Patient Manager"),
|
||||||
drawer: MyAppDrawer(drawerTitle: widget.userEmail),
|
drawer: MyAppDrawer(drawerTitle: widget.userEmail),
|
||||||
body: FutureBuilder(
|
body: FutureBuilder(
|
||||||
future: fetchPatients(endpoint + widget.userEmail),
|
future: futurePatients,
|
||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||||
return const CircularProgressIndicator();
|
return const CircularProgressIndicator();
|
||||||
} else if (snapshot.hasData) {
|
} else if (snapshot.hasData) {
|
||||||
final patientsList = snapshot.data!;
|
final patientsList = snapshot.data!;
|
||||||
return BuildPatientsList(
|
|
||||||
patients: patientsList,
|
return Column(children: [
|
||||||
);
|
//spacer
|
||||||
|
const SizedBox(height: 10),
|
||||||
|
MySearchField(
|
||||||
|
controller: searchController,
|
||||||
|
hintText: "ID Search",
|
||||||
|
onChanged: (value) {
|
||||||
|
setState(() {
|
||||||
|
searchString = value;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
//spacer
|
||||||
|
const SizedBox(height: 10),
|
||||||
|
Expanded(
|
||||||
|
child: BuildPatientsList(
|
||||||
|
patients: patientsList,
|
||||||
|
searchString: searchString,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]);
|
||||||
} else {
|
} else {
|
||||||
return const MyAppDrawer(drawerTitle: "Error pulling email");
|
return const MyAppDrawer(drawerTitle: "Error pulling email");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
// FutureBuilder<Patient>(
|
|
||||||
// future: futurePatients,
|
|
||||||
// builder: (context, snapshot) {
|
|
||||||
// if (snapshot.hasData) {
|
|
||||||
// return Scaffold(
|
|
||||||
// appBar: const MyAppBar(barTitle: "Patient Manager"),
|
|
||||||
// body: Center(child: Text(snapshot.data.toString())),
|
|
||||||
// drawer: MyAppDrawer(drawerTitle: useremail),
|
|
||||||
// );
|
|
||||||
// } else if (snapshot.hasError) {
|
|
||||||
// print('${snapshot.error}');
|
|
||||||
// return Text('${snapshot.error}');
|
|
||||||
// } else {
|
|
||||||
// return Center(child: CircularProgressIndicator());
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
// );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user