forked from yaso_meth/mih-project
Change made to cater to pass User email from home page.
This commit is contained in:
@@ -2,9 +2,8 @@ import 'package:flutter/material.dart';
|
||||
import 'package:patient_manager/components/homeTile.dart';
|
||||
|
||||
class HomeTileGrid extends StatelessWidget {
|
||||
void navigateToPage() {}
|
||||
|
||||
const HomeTileGrid({super.key});
|
||||
final String userEmail;
|
||||
const HomeTileGrid({super.key, required this.userEmail});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -20,20 +19,21 @@ class HomeTileGrid extends StatelessWidget {
|
||||
children: [
|
||||
HomeTile(
|
||||
onTap: () {
|
||||
Navigator.of(context).pushNamed('/patient-manager');
|
||||
Navigator.of(context)
|
||||
.pushNamed('/patient-manager', arguments: userEmail);
|
||||
},
|
||||
tileName: "Patient Manager",
|
||||
tileDescription:
|
||||
"This is a digital solution for doctors Offices to manage their patients",
|
||||
),
|
||||
HomeTile(
|
||||
onTap: navigateToPage,
|
||||
onTap: () {},
|
||||
tileName: "Test",
|
||||
tileDescription:
|
||||
"This is a digital solution for doctors Offices to manage their patients",
|
||||
),
|
||||
HomeTile(
|
||||
onTap: navigateToPage,
|
||||
onTap: () {},
|
||||
tileName: "Test 1",
|
||||
tileDescription:
|
||||
"This is a digital solution for doctors Offices to manage their patients",
|
||||
|
||||
@@ -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());
|
||||
// }
|
||||
// },
|
||||
// ),
|
||||
// );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
// ignore: file_names
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:patient_manager/Authentication/authCheck.dart';
|
||||
import 'package:patient_manager/components/myAppBar.dart';
|
||||
import 'package:patient_manager/components/signInOrRegister.dart';
|
||||
import 'package:patient_manager/pages/home.dart';
|
||||
import 'package:patient_manager/pages/patientManager.dart';
|
||||
|
||||
class RouteGenerator {
|
||||
static Route<dynamic> generateRoute(RouteSettings settings) {
|
||||
//final args = settings.arguments;
|
||||
final args = settings.arguments;
|
||||
|
||||
switch (settings.name) {
|
||||
case '/':
|
||||
@@ -15,7 +16,14 @@ class RouteGenerator {
|
||||
case '/home':
|
||||
return MaterialPageRoute(builder: (_) => const Home());
|
||||
case '/patient-manager':
|
||||
return MaterialPageRoute(builder: (_) => const PatientManager());
|
||||
if (args is String) {
|
||||
return MaterialPageRoute(
|
||||
builder: (_) => PatientManager(
|
||||
userEmail: args,
|
||||
),
|
||||
);
|
||||
}
|
||||
return _errorRoute();
|
||||
case '/signin':
|
||||
return MaterialPageRoute(builder: (_) => const SignInOrRegister());
|
||||
// //case '/signIn':
|
||||
@@ -26,3 +34,14 @@ class RouteGenerator {
|
||||
throw '';
|
||||
}
|
||||
}
|
||||
|
||||
Route<dynamic> _errorRoute() {
|
||||
return MaterialPageRoute(builder: (_) {
|
||||
return const Scaffold(
|
||||
appBar: MyAppBar(barTitle: "Error"),
|
||||
body: Center(
|
||||
child: Text("Error"),
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user