pat widget a signed in user instead of email
This commit is contained in:
@@ -1,18 +1,14 @@
|
|||||||
import 'dart:convert';
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:patient_manager/env/env.dart';
|
|
||||||
import 'package:patient_manager/main.dart';
|
import 'package:patient_manager/main.dart';
|
||||||
import 'package:supertokens_flutter/http.dart' as http;
|
|
||||||
import 'package:patient_manager/objects/appUser.dart';
|
import 'package:patient_manager/objects/appUser.dart';
|
||||||
import 'package:supertokens_flutter/supertokens.dart';
|
import 'package:supertokens_flutter/supertokens.dart';
|
||||||
|
|
||||||
class PatManAppDrawer extends StatefulWidget {
|
class PatManAppDrawer extends StatefulWidget {
|
||||||
final String userEmail;
|
final AppUser signedInUser;
|
||||||
final Image logo;
|
final Image logo;
|
||||||
const PatManAppDrawer({
|
const PatManAppDrawer({
|
||||||
super.key,
|
super.key,
|
||||||
required this.userEmail,
|
required this.signedInUser,
|
||||||
required this.logo,
|
required this.logo,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -21,27 +17,27 @@ class PatManAppDrawer extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _PatManAppDrawerState extends State<PatManAppDrawer> {
|
class _PatManAppDrawerState extends State<PatManAppDrawer> {
|
||||||
String endpointUserData = "${AppEnviroment.baseApiUrl}/users/profile/";
|
//String endpointUserData = "${AppEnviroment.baseApiUrl}/users/profile/";
|
||||||
late Future<AppUser> signedInUser;
|
//late Future<AppUser> signedInUser;
|
||||||
//late Image logo;
|
//late Image logo;
|
||||||
|
|
||||||
Future<AppUser> getUserDetails() async {
|
// Future<AppUser> getUserDetails() async {
|
||||||
//print("pat man drawer: " + endpointUserData + widget.userEmail);
|
// //print("pat man drawer: " + endpointUserData + widget.userEmail);
|
||||||
var response =
|
// var response =
|
||||||
await http.get(Uri.parse(endpointUserData + widget.userEmail));
|
// await http.get(Uri.parse(endpointUserData + widget.signedInUser));
|
||||||
// print(response.statusCode);
|
// // print(response.statusCode);
|
||||||
//print(response.body);
|
// //print(response.body);
|
||||||
if (response.statusCode == 200) {
|
// if (response.statusCode == 200) {
|
||||||
//print("here");
|
// //print("here");
|
||||||
String body = response.body;
|
// String body = response.body;
|
||||||
var decodedData = jsonDecode(body);
|
// var decodedData = jsonDecode(body);
|
||||||
AppUser u = AppUser.fromJson(decodedData as Map<String, dynamic>);
|
// AppUser u = AppUser.fromJson(decodedData as Map<String, dynamic>);
|
||||||
//print(u.email);
|
// //print(u.email);
|
||||||
return u;
|
// return u;
|
||||||
} else {
|
// } else {
|
||||||
throw Exception("Error: GetUserData status code ${response.statusCode}");
|
// throw Exception("Error: GetUserData status code ${response.statusCode}");
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
Future<bool> signOut() async {
|
Future<bool> signOut() async {
|
||||||
await SuperTokens.signOut(completionHandler: (error) {
|
await SuperTokens.signOut(completionHandler: (error) {
|
||||||
@@ -52,7 +48,7 @@ class _PatManAppDrawerState extends State<PatManAppDrawer> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
signedInUser = getUserDetails();
|
//signedInUser = getUserDetails();
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,193 +56,169 @@ class _PatManAppDrawerState extends State<PatManAppDrawer> {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
// precacheImage(
|
// precacheImage(
|
||||||
// MzanziInnovationHub.of(context)!.theme.logoImage().image, context);
|
// MzanziInnovationHub.of(context)!.theme.logoImage().image, context);
|
||||||
return FutureBuilder(
|
return Drawer(
|
||||||
future: signedInUser,
|
//backgroundColor: MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
||||||
builder: (BuildContext context, AsyncSnapshot<AppUser> snapshot) {
|
child: Stack(children: [
|
||||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
ListView(
|
||||||
return const Center(
|
padding: EdgeInsets.zero,
|
||||||
child: CircularProgressIndicator(),
|
children: [
|
||||||
);
|
DrawerHeader(
|
||||||
} else if (snapshot.hasData) {
|
decoration: BoxDecoration(
|
||||||
return Drawer(
|
color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||||
//backgroundColor: MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
),
|
||||||
child: Stack(children: [
|
child: SizedBox(
|
||||||
ListView(
|
height: 400,
|
||||||
padding: EdgeInsets.zero,
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
SizedBox(
|
||||||
|
height: 60,
|
||||||
|
child: widget.logo,
|
||||||
|
),
|
||||||
|
const SizedBox(height: 50),
|
||||||
|
Row(
|
||||||
|
mainAxisSize: MainAxisSize.max,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
"Username: ",
|
||||||
|
style: TextStyle(
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
color: MzanziInnovationHub.of(context)!
|
||||||
|
.theme
|
||||||
|
.primaryColor(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 15),
|
||||||
|
Text(
|
||||||
|
widget.signedInUser.username,
|
||||||
|
style: TextStyle(
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
color: MzanziInnovationHub.of(context)!
|
||||||
|
.theme
|
||||||
|
.primaryColor(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
ListTile(
|
||||||
|
title: Row(
|
||||||
|
mainAxisSize: MainAxisSize.max,
|
||||||
children: [
|
children: [
|
||||||
DrawerHeader(
|
Icon(
|
||||||
decoration: BoxDecoration(
|
Icons.home_outlined,
|
||||||
|
color:
|
||||||
|
MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 25.0),
|
||||||
|
Text(
|
||||||
|
"Home",
|
||||||
|
style: TextStyle(
|
||||||
|
//fontWeight: FontWeight.bold,
|
||||||
color: MzanziInnovationHub.of(context)!
|
color: MzanziInnovationHub.of(context)!
|
||||||
.theme
|
.theme
|
||||||
.secondaryColor(),
|
.secondaryColor(),
|
||||||
),
|
),
|
||||||
child: SizedBox(
|
|
||||||
height: 400,
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
SizedBox(
|
|
||||||
height: 60,
|
|
||||||
child: widget.logo,
|
|
||||||
),
|
|
||||||
const SizedBox(height: 50),
|
|
||||||
Row(
|
|
||||||
mainAxisSize: MainAxisSize.max,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
"Username: ",
|
|
||||||
style: TextStyle(
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
color: MzanziInnovationHub.of(context)!
|
|
||||||
.theme
|
|
||||||
.primaryColor(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 15),
|
|
||||||
Text(
|
|
||||||
"${snapshot.data?.username}",
|
|
||||||
style: TextStyle(
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
color: MzanziInnovationHub.of(context)!
|
|
||||||
.theme
|
|
||||||
.primaryColor(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
ListTile(
|
|
||||||
title: Row(
|
|
||||||
mainAxisSize: MainAxisSize.max,
|
|
||||||
children: [
|
|
||||||
Icon(
|
|
||||||
Icons.home_outlined,
|
|
||||||
color: MzanziInnovationHub.of(context)!
|
|
||||||
.theme
|
|
||||||
.secondaryColor(),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 25.0),
|
|
||||||
Text(
|
|
||||||
"Home",
|
|
||||||
style: TextStyle(
|
|
||||||
//fontWeight: FontWeight.bold,
|
|
||||||
color: MzanziInnovationHub.of(context)!
|
|
||||||
.theme
|
|
||||||
.secondaryColor(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
onTap: () {
|
|
||||||
//Navigator.of(context).pushNamed('/home');
|
|
||||||
Navigator.popAndPushNamed(context, '/home');
|
|
||||||
},
|
|
||||||
),
|
|
||||||
ListTile(
|
|
||||||
title: Row(
|
|
||||||
mainAxisSize: MainAxisSize.max,
|
|
||||||
children: [
|
|
||||||
Icon(
|
|
||||||
Icons.perm_identity,
|
|
||||||
color: MzanziInnovationHub.of(context)!
|
|
||||||
.theme
|
|
||||||
.secondaryColor(),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 25.0),
|
|
||||||
Text(
|
|
||||||
"Profile",
|
|
||||||
style: TextStyle(
|
|
||||||
//fontWeight: FontWeight.bold,
|
|
||||||
color: MzanziInnovationHub.of(context)!
|
|
||||||
.theme
|
|
||||||
.secondaryColor(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
onTap: () {
|
|
||||||
//signedInUser = snapshot.data!;
|
|
||||||
//print("PatManAppDrawer: ${signedInUser.runtimeType}");
|
|
||||||
Navigator.of(context)
|
|
||||||
.pushNamed('/profile', arguments: snapshot.data);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
ListTile(
|
|
||||||
title: Row(
|
|
||||||
mainAxisSize: MainAxisSize.max,
|
|
||||||
children: [
|
|
||||||
Icon(
|
|
||||||
Icons.logout,
|
|
||||||
color: MzanziInnovationHub.of(context)!
|
|
||||||
.theme
|
|
||||||
.secondaryColor(),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 25.0),
|
|
||||||
Text(
|
|
||||||
"Sign Out",
|
|
||||||
style: TextStyle(
|
|
||||||
//fontWeight: FontWeight.bold,
|
|
||||||
color: MzanziInnovationHub.of(context)!
|
|
||||||
.theme
|
|
||||||
.secondaryColor(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
onTap: () async {
|
|
||||||
await SuperTokens.signOut(completionHandler: (error) {
|
|
||||||
print(error);
|
|
||||||
});
|
|
||||||
if (await SuperTokens.doesSessionExist() == false) {
|
|
||||||
Navigator.of(context).pushNamed('/');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
)
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
Positioned(
|
onTap: () {
|
||||||
top: 1,
|
//Navigator.of(context).pushNamed('/home');
|
||||||
right: 1,
|
Navigator.popAndPushNamed(context, '/home');
|
||||||
width: 50,
|
},
|
||||||
height: 50,
|
),
|
||||||
child: IconButton(
|
ListTile(
|
||||||
onPressed: () {
|
title: Row(
|
||||||
setState(() {
|
mainAxisSize: MainAxisSize.max,
|
||||||
if (MzanziInnovationHub.of(context)?.theme.mode ==
|
children: [
|
||||||
"Dark") {
|
Icon(
|
||||||
//darkm = !darkm;
|
Icons.perm_identity,
|
||||||
MzanziInnovationHub.of(context)!
|
|
||||||
.changeTheme(ThemeMode.light);
|
|
||||||
//print("Dark Mode: $darkm");
|
|
||||||
} else {
|
|
||||||
//darkm = !darkm;
|
|
||||||
MzanziInnovationHub.of(context)!
|
|
||||||
.changeTheme(ThemeMode.dark);
|
|
||||||
//print("Dark Mode: $darkm");
|
|
||||||
}
|
|
||||||
Navigator.of(context).pushNamed('/home');
|
|
||||||
});
|
|
||||||
},
|
|
||||||
icon: Icon(
|
|
||||||
Icons.light_mode,
|
|
||||||
color:
|
color:
|
||||||
MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||||
size: 35,
|
|
||||||
),
|
),
|
||||||
),
|
const SizedBox(width: 25.0),
|
||||||
|
Text(
|
||||||
|
"Profile",
|
||||||
|
style: TextStyle(
|
||||||
|
//fontWeight: FontWeight.bold,
|
||||||
|
color: MzanziInnovationHub.of(context)!
|
||||||
|
.theme
|
||||||
|
.secondaryColor(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
]),
|
onTap: () {
|
||||||
);
|
//signedInUser = snapshot.data!;
|
||||||
} else {
|
//print("PatManAppDrawer: ${signedInUser.runtimeType}");
|
||||||
return const Center(
|
Navigator.of(context)
|
||||||
child: Text("Error Loading profile"),
|
.pushNamed('/profile', arguments: widget.signedInUser);
|
||||||
);
|
},
|
||||||
}
|
),
|
||||||
},
|
ListTile(
|
||||||
|
title: Row(
|
||||||
|
mainAxisSize: MainAxisSize.max,
|
||||||
|
children: [
|
||||||
|
Icon(
|
||||||
|
Icons.logout,
|
||||||
|
color:
|
||||||
|
MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 25.0),
|
||||||
|
Text(
|
||||||
|
"Sign Out",
|
||||||
|
style: TextStyle(
|
||||||
|
//fontWeight: FontWeight.bold,
|
||||||
|
color: MzanziInnovationHub.of(context)!
|
||||||
|
.theme
|
||||||
|
.secondaryColor(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
onTap: () async {
|
||||||
|
await SuperTokens.signOut(completionHandler: (error) {
|
||||||
|
print(error);
|
||||||
|
});
|
||||||
|
if (await SuperTokens.doesSessionExist() == false) {
|
||||||
|
Navigator.of(context).pushNamed('/');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
Positioned(
|
||||||
|
top: 1,
|
||||||
|
right: 1,
|
||||||
|
width: 50,
|
||||||
|
height: 50,
|
||||||
|
child: IconButton(
|
||||||
|
onPressed: () {
|
||||||
|
setState(() {
|
||||||
|
if (MzanziInnovationHub.of(context)?.theme.mode == "Dark") {
|
||||||
|
//darkm = !darkm;
|
||||||
|
MzanziInnovationHub.of(context)!.changeTheme(ThemeMode.light);
|
||||||
|
//print("Dark Mode: $darkm");
|
||||||
|
} else {
|
||||||
|
//darkm = !darkm;
|
||||||
|
MzanziInnovationHub.of(context)!.changeTheme(ThemeMode.dark);
|
||||||
|
//print("Dark Mode: $darkm");
|
||||||
|
}
|
||||||
|
Navigator.of(context).pushNamed('/home');
|
||||||
|
});
|
||||||
|
},
|
||||||
|
icon: Icon(
|
||||||
|
Icons.light_mode,
|
||||||
|
color: MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
||||||
|
size: 35,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user