Get user email on home screen
This commit is contained in:
Binary file not shown.
BIN
Binary file not shown.
@@ -1,7 +1,10 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:patient_manager/main.dart';
|
import 'package:patient_manager/main.dart';
|
||||||
|
|
||||||
class MyAppBar extends StatelessWidget {
|
class MyAppBar extends StatelessWidget implements PreferredSizeWidget {
|
||||||
|
@override
|
||||||
|
Size get preferredSize => const Size.fromHeight(60);
|
||||||
|
|
||||||
final String barTitle;
|
final String barTitle;
|
||||||
|
|
||||||
const MyAppBar({super.key, required this.barTitle});
|
const MyAppBar({super.key, required this.barTitle});
|
||||||
|
|||||||
@@ -12,6 +12,18 @@ class MyAppDrawer extends StatefulWidget {
|
|||||||
class _MyAppDrawerState extends State<MyAppDrawer> {
|
class _MyAppDrawerState extends State<MyAppDrawer> {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Drawer();
|
return Drawer(
|
||||||
|
child: ListView(
|
||||||
|
padding: EdgeInsets.zero,
|
||||||
|
children: [
|
||||||
|
DrawerHeader(
|
||||||
|
child: Text(widget.drawerTitle as String),
|
||||||
|
decoration: const BoxDecoration(
|
||||||
|
color: Colors.blueAccent,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,49 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:patient_manager/components/homeTileGrid.dart';
|
import 'package:patient_manager/components/homeTileGrid.dart';
|
||||||
import 'package:patient_manager/components/myAppBar.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 {
|
class Home extends StatefulWidget {
|
||||||
const Home({super.key});
|
//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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return const Scaffold(
|
return FutureBuilder(
|
||||||
appBar: PreferredSize(
|
future: getUserEmail(),
|
||||||
preferredSize: Size.fromHeight(50),
|
builder: (context, snapshot) {
|
||||||
child: MyAppBar(
|
if (snapshot.connectionState == ConnectionState.done) {
|
||||||
barTitle: "Mzanzi Innovation Hub",
|
return Scaffold(
|
||||||
),
|
appBar: MyAppBar(barTitle: "Mzanzi Innovation Hub"),
|
||||||
),
|
body: HomeTileGrid(),
|
||||||
body: HomeTileGrid(),
|
drawer: MyAppDrawer(drawerTitle: useremail),
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
return Center(child: CircularProgressIndicator());
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,21 +17,28 @@ class _RegisterState extends State<Register> {
|
|||||||
final emailController = TextEditingController();
|
final emailController = TextEditingController();
|
||||||
final passwordController = TextEditingController();
|
final passwordController = TextEditingController();
|
||||||
final confirmPasswordController = TextEditingController();
|
final confirmPasswordController = TextEditingController();
|
||||||
|
final officeID = TextEditingController();
|
||||||
|
|
||||||
bool _obscureText = true;
|
bool _obscureText = true;
|
||||||
//sign user in
|
//sign user in
|
||||||
Future<void> signUserUp() async {
|
Future<void> signUserUp() async {
|
||||||
try {
|
if (passwordController.text != confirmPasswordController.text) {
|
||||||
final response = await client.auth.signUp(
|
loginError("Passwords do not match");
|
||||||
email: emailController.text,
|
} else {
|
||||||
password: passwordController.text,
|
try {
|
||||||
);
|
final response = await client.auth.signUp(
|
||||||
if (response.session != null) {
|
email: emailController.text,
|
||||||
Navigator.of(context).pushNamed('/homme');
|
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
|
//spacer
|
||||||
const SizedBox(height: 25),
|
const SizedBox(height: 25),
|
||||||
//email input
|
//email input
|
||||||
|
SizedBox(
|
||||||
|
width: 500.0,
|
||||||
|
child: MyTextField(
|
||||||
|
controller: officeID,
|
||||||
|
hintText: 'OfficeID',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
//spacer
|
||||||
|
const SizedBox(height: 25),
|
||||||
|
//email input
|
||||||
SizedBox(
|
SizedBox(
|
||||||
width: 500.0,
|
width: 500.0,
|
||||||
child: MyTextField(
|
child: MyTextField(
|
||||||
@@ -128,7 +145,7 @@ class _RegisterState extends State<Register> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
//spacer
|
//spacer
|
||||||
const SizedBox(height: 50),
|
const SizedBox(height: 30),
|
||||||
// sign up button
|
// sign up button
|
||||||
SizedBox(
|
SizedBox(
|
||||||
width: 500.0,
|
width: 500.0,
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ class _SignInState extends State<SignIn> {
|
|||||||
password: passwordController.text,
|
password: passwordController.text,
|
||||||
);
|
);
|
||||||
if (response.session != null) {
|
if (response.session != null) {
|
||||||
Navigator.of(context).pushNamed('/homme');
|
Navigator.of(context).pushNamed('/homme', arguments: "Yaso");
|
||||||
}
|
}
|
||||||
} on AuthException catch (error) {
|
} on AuthException catch (error) {
|
||||||
loginError(error.message);
|
loginError(error.message);
|
||||||
|
|||||||
@@ -5,13 +5,18 @@ import 'package:patient_manager/pages/home.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 '/':
|
||||||
return MaterialPageRoute(builder: (_) => AuthCheck());
|
return MaterialPageRoute(builder: (_) => AuthCheck());
|
||||||
case '/home':
|
case '/home':
|
||||||
return MaterialPageRoute(builder: (_) => const Home());
|
if (args is String) {
|
||||||
|
return MaterialPageRoute(
|
||||||
|
builder: (_) => const Home(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// case '/signin':
|
// case '/signin':
|
||||||
// return MaterialPageRoute(builder: (_) => const SignInOrRegister());
|
// return MaterialPageRoute(builder: (_) => const SignInOrRegister());
|
||||||
// //case '/signIn':
|
// //case '/signIn':
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user