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';
|
import 'package:patient_manager/components/homeTile.dart';
|
||||||
|
|
||||||
class HomeTileGrid extends StatelessWidget {
|
class HomeTileGrid extends StatelessWidget {
|
||||||
void navigateToPage() {}
|
final String userEmail;
|
||||||
|
const HomeTileGrid({super.key, required this.userEmail});
|
||||||
const HomeTileGrid({super.key});
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@@ -20,20 +19,21 @@ class HomeTileGrid extends StatelessWidget {
|
|||||||
children: [
|
children: [
|
||||||
HomeTile(
|
HomeTile(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.of(context).pushNamed('/patient-manager');
|
Navigator.of(context)
|
||||||
|
.pushNamed('/patient-manager', arguments: userEmail);
|
||||||
},
|
},
|
||||||
tileName: "Patient Manager",
|
tileName: "Patient Manager",
|
||||||
tileDescription:
|
tileDescription:
|
||||||
"This is a digital solution for doctors Offices to manage their patients",
|
"This is a digital solution for doctors Offices to manage their patients",
|
||||||
),
|
),
|
||||||
HomeTile(
|
HomeTile(
|
||||||
onTap: navigateToPage,
|
onTap: () {},
|
||||||
tileName: "Test",
|
tileName: "Test",
|
||||||
tileDescription:
|
tileDescription:
|
||||||
"This is a digital solution for doctors Offices to manage their patients",
|
"This is a digital solution for doctors Offices to manage their patients",
|
||||||
),
|
),
|
||||||
HomeTile(
|
HomeTile(
|
||||||
onTap: navigateToPage,
|
onTap: () {},
|
||||||
tileName: "Test 1",
|
tileName: "Test 1",
|
||||||
tileDescription:
|
tileDescription:
|
||||||
"This is a digital solution for doctors Offices to manage their patients",
|
"This is a digital solution for doctors Offices to manage their patients",
|
||||||
|
|||||||
@@ -32,19 +32,38 @@ class _HomeState extends State<Home> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return FutureBuilder(
|
||||||
appBar: MyAppBar(barTitle: "Mzanzi Innovation Hub"),
|
future: getUserEmail(),
|
||||||
body: HomeTileGrid(),
|
builder: (contexts, snapshot) {
|
||||||
drawer: FutureBuilder(
|
if (snapshot.connectionState == ConnectionState.done) {
|
||||||
future: getUserEmail(),
|
return Scaffold(
|
||||||
builder: (contexts, snapshot) {
|
appBar: MyAppBar(barTitle: "Mzanzi Innovation Hub"),
|
||||||
if (snapshot.connectionState == ConnectionState.done) {
|
drawer: MyAppDrawer(
|
||||||
return MyAppDrawer(drawerTitle: useremail);
|
drawerTitle: useremail,
|
||||||
} else {
|
),
|
||||||
return Center(child: CircularProgressIndicator());
|
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:mysql_client/mysql_client.dart';
|
||||||
import 'package:patient_manager/objects/patients.dart';
|
import 'package:patient_manager/objects/patients.dart';
|
||||||
|
|
||||||
Future<List<Patient>> fetchPatients() async {
|
Future<List<Patient>> fetchPatients(String endpoint) async {
|
||||||
print("fetch patients");
|
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());
|
//print("Status Code: " + response.statusCode.toString());
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
Iterable l = jsonDecode(response.body);
|
Iterable l = jsonDecode(response.body);
|
||||||
@@ -30,54 +30,57 @@ Future<List<Patient>> fetchPatients() async {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class PatientManager extends StatefulWidget {
|
class PatientManager extends StatefulWidget {
|
||||||
const PatientManager({super.key});
|
final String userEmail;
|
||||||
|
|
||||||
|
const PatientManager({
|
||||||
|
super.key,
|
||||||
|
required this.userEmail,
|
||||||
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<PatientManager> createState() => _PatientManagerState();
|
State<PatientManager> createState() => _PatientManagerState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _PatientManagerState extends State<PatientManager> {
|
class _PatientManagerState extends State<PatientManager> {
|
||||||
String useremail = "";
|
//String useremail = "";
|
||||||
String endpoint = "http://localhost:80/patients/";
|
String endpoint = "http://localhost:80/patients/user/";
|
||||||
late MySQLConnection conn;
|
late MySQLConnection conn;
|
||||||
String resultsofDB = "";
|
String resultsofDB = "";
|
||||||
late Future<List<Patient>> futurePatients;
|
late Future<List<Patient>> futurePatients;
|
||||||
|
|
||||||
Future<void> getuserEmail() async {
|
// Future<String> getuserEmail() async {
|
||||||
final res = await client.auth.getUser();
|
// final res = await client.auth.getUser();
|
||||||
//final response = await http.get(Uri.parse(endpoint));
|
// //final response = await http.get(Uri.parse(endpoint));
|
||||||
//print(json.decode(response.body));
|
// //print(json.decode(response.body));
|
||||||
if (res.user!.email != null) {
|
// if (res.user!.email != null) {
|
||||||
print("User: " + res.user!.email.toString());
|
// //print("User: " + res.user!.email.toString());
|
||||||
useremail = res.user!.email!;
|
// useremail = res.user!.email!;
|
||||||
print(useremail);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
// //print(useremail);
|
||||||
void initState() {
|
// return useremail;
|
||||||
print("init now");
|
// }
|
||||||
getuserEmail();
|
// return "";
|
||||||
futurePatients = fetchPatients();
|
// }
|
||||||
super.initState();
|
|
||||||
}
|
// @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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: const MyAppBar(barTitle: "Patient Manager"),
|
appBar: const MyAppBar(barTitle: "Patient Manager"),
|
||||||
drawer: FutureBuilder(
|
drawer: MyAppDrawer(drawerTitle: widget.userEmail),
|
||||||
future: getuserEmail(),
|
|
||||||
builder: (context, snapshot) {
|
|
||||||
if (snapshot.hasData) {
|
|
||||||
return MyAppDrawer(drawerTitle: useremail);
|
|
||||||
} else {
|
|
||||||
return const MyAppDrawer(drawerTitle: "Error pulling email");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
body: FutureBuilder(
|
body: FutureBuilder(
|
||||||
future: futurePatients,
|
future: fetchPatients(endpoint + widget.userEmail),
|
||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||||
return const CircularProgressIndicator();
|
return const CircularProgressIndicator();
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
// ignore: file_names
|
// ignore: file_names
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:patient_manager/Authentication/authCheck.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/components/signInOrRegister.dart';
|
||||||
import 'package:patient_manager/pages/home.dart';
|
import 'package:patient_manager/pages/home.dart';
|
||||||
import 'package:patient_manager/pages/patientManager.dart';
|
import 'package:patient_manager/pages/patientManager.dart';
|
||||||
|
|
||||||
class RouteGenerator {
|
class RouteGenerator {
|
||||||
static Route<dynamic> generateRoute(RouteSettings settings) {
|
static Route<dynamic> generateRoute(RouteSettings settings) {
|
||||||
//final args = settings.arguments;
|
final args = settings.arguments;
|
||||||
|
|
||||||
switch (settings.name) {
|
switch (settings.name) {
|
||||||
case '/':
|
case '/':
|
||||||
@@ -15,7 +16,14 @@ class RouteGenerator {
|
|||||||
case '/home':
|
case '/home':
|
||||||
return MaterialPageRoute(builder: (_) => const Home());
|
return MaterialPageRoute(builder: (_) => const Home());
|
||||||
case '/patient-manager':
|
case '/patient-manager':
|
||||||
return MaterialPageRoute(builder: (_) => const PatientManager());
|
if (args is String) {
|
||||||
|
return MaterialPageRoute(
|
||||||
|
builder: (_) => PatientManager(
|
||||||
|
userEmail: args,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return _errorRoute();
|
||||||
case '/signin':
|
case '/signin':
|
||||||
return MaterialPageRoute(builder: (_) => const SignInOrRegister());
|
return MaterialPageRoute(builder: (_) => const SignInOrRegister());
|
||||||
// //case '/signIn':
|
// //case '/signIn':
|
||||||
@@ -26,3 +34,14 @@ class RouteGenerator {
|
|||||||
throw '';
|
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