Change made to cater to pass User email from home page.

This commit is contained in:
2024-04-07 13:29:01 +02:00
parent 15eeed1872
commit 0df2161879
4 changed files with 95 additions and 54 deletions

View File

@@ -32,19 +32,38 @@ class _HomeState extends State<Home> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: MyAppBar(barTitle: "Mzanzi Innovation Hub"),
body: HomeTileGrid(),
drawer: FutureBuilder(
future: getUserEmail(),
builder: (contexts, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return MyAppDrawer(drawerTitle: useremail);
} else {
return Center(child: CircularProgressIndicator());
}
},
),
return FutureBuilder(
future: getUserEmail(),
builder: (contexts, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return Scaffold(
appBar: MyAppBar(barTitle: "Mzanzi Innovation Hub"),
drawer: MyAppDrawer(
drawerTitle: useremail,
),
body: HomeTileGrid(
userEmail: useremail,
),
);
} else {
return Center(child: CircularProgressIndicator());
}
},
);
// Scaffold(
// appBar: MyAppBar(barTitle: "Mzanzi Innovation Hub"),
// body: HomeTileGrid(),
// drawer: FutureBuilder(
// future: getUserEmail(),
// builder: (contexts, snapshot) {
// if (snapshot.connectionState == ConnectionState.done) {
// return MyAppDrawer(drawerTitle: useremail);
// } else {
// return Center(child: CircularProgressIndicator());
// }
// },
// ),
// );
}
}

View File

@@ -10,9 +10,9 @@ import 'package:http/http.dart' as http;
import 'package:mysql_client/mysql_client.dart';
import 'package:patient_manager/objects/patients.dart';
Future<List<Patient>> fetchPatients() async {
Future<List<Patient>> fetchPatients(String endpoint) async {
print("fetch patients");
final response = await http.get(Uri.parse('http://localhost:80/patients/'));
final response = await http.get(Uri.parse(endpoint));
//print("Status Code: " + response.statusCode.toString());
if (response.statusCode == 200) {
Iterable l = jsonDecode(response.body);
@@ -30,54 +30,57 @@ Future<List<Patient>> fetchPatients() async {
}
class PatientManager extends StatefulWidget {
const PatientManager({super.key});
final String userEmail;
const PatientManager({
super.key,
required this.userEmail,
});
@override
State<PatientManager> createState() => _PatientManagerState();
}
class _PatientManagerState extends State<PatientManager> {
String useremail = "";
String endpoint = "http://localhost:80/patients/";
//String useremail = "";
String endpoint = "http://localhost:80/patients/user/";
late MySQLConnection conn;
String resultsofDB = "";
late Future<List<Patient>> futurePatients;
Future<void> getuserEmail() async {
final res = await client.auth.getUser();
//final response = await http.get(Uri.parse(endpoint));
//print(json.decode(response.body));
if (res.user!.email != null) {
print("User: " + res.user!.email.toString());
useremail = res.user!.email!;
print(useremail);
}
}
// Future<String> getuserEmail() async {
// final res = await client.auth.getUser();
// //final response = await http.get(Uri.parse(endpoint));
// //print(json.decode(response.body));
// if (res.user!.email != null) {
// //print("User: " + res.user!.email.toString());
// useremail = res.user!.email!;
@override
void initState() {
print("init now");
getuserEmail();
futurePatients = fetchPatients();
super.initState();
}
// //print(useremail);
// return useremail;
// }
// return "";
// }
// @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
Widget build(BuildContext context) {
return Scaffold(
appBar: const MyAppBar(barTitle: "Patient Manager"),
drawer: FutureBuilder(
future: getuserEmail(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return MyAppDrawer(drawerTitle: useremail);
} else {
return const MyAppDrawer(drawerTitle: "Error pulling email");
}
},
),
drawer: MyAppDrawer(drawerTitle: widget.userEmail),
body: FutureBuilder(
future: futurePatients,
future: fetchPatients(endpoint + widget.userEmail),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const CircularProgressIndicator();