2) remove Unnesasay signed in user from widget, add menu height. 3) add medicine object to cater for results of med api call. 4) update search input to cater for new parameters. 5) create prescriotion popUp widget. 6) Create medicine search pop Up widget
120 lines
3.7 KiB
Dart
120 lines
3.7 KiB
Dart
import 'dart:async';
|
|
import 'dart:convert';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:patient_manager/components/buildPatientList.dart';
|
|
import 'package:patient_manager/components/myAppBar.dart';
|
|
import 'package:http/http.dart' as http;
|
|
import 'package:patient_manager/components/mySearchInput.dart';
|
|
import 'package:patient_manager/components/patManAppDrawer.dart';
|
|
import 'package:patient_manager/objects/patients.dart';
|
|
|
|
class PatientManager extends StatefulWidget {
|
|
final String userEmail;
|
|
|
|
const PatientManager({
|
|
super.key,
|
|
required this.userEmail,
|
|
});
|
|
|
|
@override
|
|
State<PatientManager> createState() => _PatientManagerState();
|
|
}
|
|
|
|
class _PatientManagerState extends State<PatientManager> {
|
|
TextEditingController searchController = TextEditingController();
|
|
String endpoint = "http://localhost:80/patients/user/";
|
|
late Future<List<Patient>> futurePatients;
|
|
String searchString = "";
|
|
|
|
Future<List<Patient>> fetchPatients(String endpoint) async {
|
|
//print("Patien manager page: $endpoint");
|
|
final response = await http.get(Uri.parse(endpoint));
|
|
//print(response.statusCode);
|
|
if (response.statusCode == 200) {
|
|
Iterable l = jsonDecode(response.body);
|
|
List<Patient> patients =
|
|
List<Patient>.from(l.map((model) => Patient.fromJson(model)));
|
|
return patients;
|
|
} else {
|
|
throw Exception('failed to load patients');
|
|
}
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
futurePatients = fetchPatients(endpoint + widget.userEmail);
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
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,
|
|
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: FutureBuilder(
|
|
future: futurePatients,
|
|
builder: (context, snapshot) {
|
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
|
return const Center(child: CircularProgressIndicator());
|
|
} else if (snapshot.hasData) {
|
|
final patientsList = snapshot.data!;
|
|
|
|
return 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),
|
|
Expanded(
|
|
child: BuildPatientsList(
|
|
patients: patientsList,
|
|
searchString: searchString,
|
|
),
|
|
),
|
|
]),
|
|
),
|
|
],
|
|
);
|
|
} else {
|
|
return const PatManAppDrawer(userEmail: "Error pulling email");
|
|
}
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|