From 0bf718d2cdf2860ee64eba859c371b7e0f0657dc Mon Sep 17 00:00:00 2001 From: yaso-meth Date: Fri, 5 Jul 2024 18:23:14 +0200 Subject: [PATCH] clean code & change look and feel --- .../lib/pages/patientManager.dart | 164 +++++++++++------- 1 file changed, 98 insertions(+), 66 deletions(-) diff --git a/Frontend/patient_manager/lib/pages/patientManager.dart b/Frontend/patient_manager/lib/pages/patientManager.dart index 9fedd19a..304c090b 100644 --- a/Frontend/patient_manager/lib/pages/patientManager.dart +++ b/Frontend/patient_manager/lib/pages/patientManager.dart @@ -25,8 +25,7 @@ class _PatientManagerState extends State { TextEditingController searchController = TextEditingController(); String endpoint = "http://localhost:80/patients/user/"; late Future> futurePatients; - // late Widget displayWidget; - //List tempList; + String searchString = ""; Future> fetchPatients(String endpoint) async { @@ -51,20 +50,90 @@ class _PatientManagerState extends State { Widget displayList(List patientsList, String searchString) { if (searchString.isNotEmpty && searchString != "") { - return BuildPatientsList( - patients: patientsList, - searchString: searchString, + return Padding( + padding: const EdgeInsets.only( + left: 25, + right: 25, + bottom: 25, + ), + child: Container( + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(25.0), + border: Border.all(color: Colors.blueAccent, width: 3.0), + ), + child: 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, + return Padding( + padding: const EdgeInsets.only( + left: 25, + right: 25, + bottom: 25, + ), + child: Container( + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(25.0), + border: Border.all(color: Colors.blueAccent, width: 3.0), + ), + child: const Center( + child: Text( + "Enter ID of Patient", + style: TextStyle(fontSize: 25, color: Colors.grey), + textAlign: TextAlign.center, + ), + ), ), ); } + Widget patientSearch() { + return 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), + FutureBuilder( + future: futurePatients, + builder: (context, snapshot) { + if (snapshot.connectionState == ConnectionState.waiting) { + return const Center(child: CircularProgressIndicator()); + } else if (snapshot.hasData) { + List patientsList; + if (searchString == "") { + patientsList = snapshot.data!; + } else { + patientsList = filterSearchResults(snapshot.data!, searchString); + } + + return Expanded( + child: displayList(patientsList, searchString), + ); + } else { + return const PatManAppDrawer(userEmail: "Error pulling email"); + } + }, + ), + ]); + } + @override void initState() { futurePatients = fetchPatients(endpoint + widget.userEmail); @@ -76,69 +145,32 @@ class _PatientManagerState extends State { return Scaffold( appBar: const MyAppBar(barTitle: "Patient Manager"), drawer: PatManAppDrawer(userEmail: widget.userEmail), - //floatingActionButtonLocation: FloatingActionButtonLocation.endTop, - floatingActionButton: FloatingActionButton.extended( - label: const Text( - "Add Patient", - style: TextStyle( - fontWeight: FontWeight.bold, + floatingActionButtonLocation: FloatingActionButtonLocation.endTop, + floatingActionButton: Padding( + padding: const EdgeInsets.only(top: 65, right: 5), + child: FloatingActionButton.extended( + label: const Text( + "Add Patient", + style: TextStyle( + fontWeight: FontWeight.bold, + color: Colors.white, + ), + ), + backgroundColor: Colors.blueAccent, + onPressed: () { + Navigator.of(context) + .pushNamed('/patient-manager/add', arguments: widget.userEmail); + }, + icon: const Icon( + Icons.add, color: Colors.white, ), ), - backgroundColor: Colors.blueAccent, - onPressed: () { - Navigator.of(context) - .pushNamed('/patient-manager/add', arguments: widget.userEmail); - }, - icon: const Icon( - Icons.add, - color: Colors.white, - ), ), body: Row( 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), - FutureBuilder( - future: futurePatients, - builder: (context, snapshot) { - if (snapshot.connectionState == ConnectionState.waiting) { - return const Center(child: CircularProgressIndicator()); - } else if (snapshot.hasData) { - List patientsList; - if (searchString == "") { - patientsList = snapshot.data!; - } else { - patientsList = - filterSearchResults(snapshot.data!, searchString); - } - - return Expanded( - child: displayList(patientsList, searchString), - ); - } else { - return const PatManAppDrawer( - userEmail: "Error pulling email"); - } - }, - ), - ]), + child: patientSearch(), ), ], ),