Enable search function on patient manager

This commit is contained in:
2024-04-07 14:12:43 +02:00
parent 0df2161879
commit 9c8406367e
3 changed files with 90 additions and 59 deletions

View File

@@ -3,9 +3,11 @@ import 'package:patient_manager/objects/patients.dart';
class BuildPatientsList extends StatefulWidget {
final List<Patient> patients;
final searchString;
const BuildPatientsList({
super.key,
required this.patients,
required this.searchString,
});
@override
@@ -18,11 +20,15 @@ class _BuildPatientsListState extends State<BuildPatientsList> {
return ListView.builder(
itemCount: widget.patients.length,
itemBuilder: (context, index) {
final patient = widget.patients[index];
return ListTile(
title: Text(patient.first_name + " " + patient.last_name),
subtitle: Text(patient.id_no),
);
//final patient = widget.patients[index].id_no.contains(widget.searchString);
return widget.patients[index].id_no.contains(widget.searchString)
? ListTile(
title: Text(widget.patients[index].first_name +
" " +
widget.patients[index].last_name),
subtitle: Text(widget.patients[index].id_no),
)
: Container();
},
);
}

View 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),
),
),
),
);
}
}