Get user email on home screen

This commit is contained in:
2024-04-06 15:05:04 +02:00
parent 8eaa3c3059
commit e17b5e24aa
29 changed files with 117 additions and 28 deletions

View File

@@ -1,20 +1,49 @@
import 'package:flutter/material.dart';
import 'package:patient_manager/components/homeTileGrid.dart';
import 'package:patient_manager/components/myAppBar.dart';
import 'package:patient_manager/components/myAppDrawer.dart';
import 'package:patient_manager/main.dart';
class Home extends StatelessWidget {
const Home({super.key});
class Home extends StatefulWidget {
//final String userEmail;
const Home({
super.key,
});
@override
State<Home> createState() => _HomeState();
}
class _HomeState extends State<Home> {
String useremail = "";
Future<void> getUserEmail() async {
final res = await client.auth.getUser();
if (res.user!.email != null) {
print("emai not null");
useremail = res.user!.email!;
print(useremail);
}
}
String getEmail() {
return useremail;
}
@override
Widget build(BuildContext context) {
return const Scaffold(
appBar: PreferredSize(
preferredSize: Size.fromHeight(50),
child: MyAppBar(
barTitle: "Mzanzi Innovation Hub",
),
),
body: HomeTileGrid(),
);
return FutureBuilder(
future: getUserEmail(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return Scaffold(
appBar: MyAppBar(barTitle: "Mzanzi Innovation Hub"),
body: HomeTileGrid(),
drawer: MyAppDrawer(drawerTitle: useremail),
);
} else {
return Center(child: CircularProgressIndicator());
}
});
}
}

View File

@@ -0,0 +1,23 @@
import 'package:flutter/material.dart';
import 'package:patient_manager/components/myAppBar.dart';
class PatientManager extends StatefulWidget {
const PatientManager({super.key});
@override
State<PatientManager> createState() => _PatientManagerState();
}
class _PatientManagerState extends State<PatientManager> {
@override
Widget build(BuildContext context) {
return const Scaffold(
appBar: PreferredSize(
preferredSize: Size.fromHeight(50),
child: MyAppBar(
barTitle: "Mzanzi Innovation Hub",
),
),
);
}
}

View File

@@ -17,21 +17,28 @@ class _RegisterState extends State<Register> {
final emailController = TextEditingController();
final passwordController = TextEditingController();
final confirmPasswordController = TextEditingController();
final officeID = TextEditingController();
bool _obscureText = true;
//sign user in
Future<void> signUserUp() async {
try {
final response = await client.auth.signUp(
email: emailController.text,
password: passwordController.text,
);
if (response.session != null) {
Navigator.of(context).pushNamed('/homme');
if (passwordController.text != confirmPasswordController.text) {
loginError("Passwords do not match");
} else {
try {
final response = await client.auth.signUp(
email: emailController.text,
password: passwordController.text,
);
if (response.session != null) {
Navigator.of(context).pushNamed('/homme');
}
} on AuthException catch (error) {
loginError(error.message);
emailController.clear();
passwordController.clear();
confirmPasswordController.clear();
}
} on AuthException catch (error) {
loginError(error.message);
emailController.clear();
passwordController.clear();
}
}
@@ -83,6 +90,16 @@ class _RegisterState extends State<Register> {
//spacer
const SizedBox(height: 25),
//email input
SizedBox(
width: 500.0,
child: MyTextField(
controller: officeID,
hintText: 'OfficeID',
),
),
//spacer
const SizedBox(height: 25),
//email input
SizedBox(
width: 500.0,
child: MyTextField(
@@ -128,7 +145,7 @@ class _RegisterState extends State<Register> {
),
),
//spacer
const SizedBox(height: 50),
const SizedBox(height: 30),
// sign up button
SizedBox(
width: 500.0,

View File

@@ -26,7 +26,7 @@ class _SignInState extends State<SignIn> {
password: passwordController.text,
);
if (response.session != null) {
Navigator.of(context).pushNamed('/homme');
Navigator.of(context).pushNamed('/homme', arguments: "Yaso");
}
} on AuthException catch (error) {
loginError(error.message);