117 lines
3.6 KiB
Dart
117 lines
3.6 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",
|
|
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");
|
|
}
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|