update authentication with supertokens
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:patient_manager/components/patManAppDrawer.dart';
|
||||
import 'package:patient_manager/env/env.dart';
|
||||
import 'package:patient_manager/components/homeTileGrid.dart';
|
||||
import 'package:patient_manager/components/myAppBar.dart';
|
||||
import 'package:patient_manager/components/homeAppDrawer.dart';
|
||||
import 'package:patient_manager/main.dart';
|
||||
import 'package:supertokens_flutter/supertokens.dart';
|
||||
import 'package:supertokens_flutter/http.dart' as http;
|
||||
|
||||
@@ -20,6 +21,26 @@ class Home extends StatefulWidget {
|
||||
class _HomeState extends State<Home> {
|
||||
String useremail = "";
|
||||
final baseAPI = AppEnviroment.baseApiUrl;
|
||||
//late Image logo;
|
||||
|
||||
Future<void> loadImage() async {
|
||||
try {
|
||||
// load network image example
|
||||
var t = MzanziInnovationHub.of(context)!.theme.logoImage();
|
||||
await precacheImage(t.image, context);
|
||||
// setState(() {
|
||||
//return MzanziInnovationHub.of(context)!.theme.logoImage();
|
||||
// });
|
||||
|
||||
// or
|
||||
// Load assets image example
|
||||
// await precacheImage(AssetImage(imagePath), context);
|
||||
//print('Image loaded and cached successfully!');
|
||||
} catch (e) {
|
||||
//return null;
|
||||
print('Failed to load and cache the image: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> getUserEmail() async {
|
||||
var uid = await SuperTokens.getUserId();
|
||||
@@ -42,12 +63,13 @@ class _HomeState extends State<Home> {
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
// TODO: implement initState
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
loadImage();
|
||||
var logo = MzanziInnovationHub.of(context)!.theme.logoImage();
|
||||
return FutureBuilder(
|
||||
future: getUserEmail(),
|
||||
builder: (contexts, snapshot) {
|
||||
@@ -55,7 +77,10 @@ class _HomeState extends State<Home> {
|
||||
//print("home page: $useremail");
|
||||
return Scaffold(
|
||||
appBar: const MyAppBar(barTitle: "Mzansi Innovation Hub"),
|
||||
drawer: HomeAppDrawer(userEmail: useremail),
|
||||
drawer: PatManAppDrawer(
|
||||
userEmail: useremail,
|
||||
logo: logo,
|
||||
), //HomeAppDrawer(userEmail: useremail),
|
||||
body: HomeTileGrid(
|
||||
userEmail: useremail,
|
||||
),
|
||||
|
||||
@@ -50,7 +50,7 @@ class _AddPatientState extends State<AddPatient> {
|
||||
var decodedData = jsonDecode(body);
|
||||
AppUser u = AppUser.fromJson(decodedData as Map<String, dynamic>);
|
||||
setState(() {
|
||||
futureDocOfficeId = u.docOffice_ID;
|
||||
futureDocOfficeId = u.docOffice_id;
|
||||
//print(futureDocOfficeId);
|
||||
});
|
||||
} else {
|
||||
|
||||
@@ -57,7 +57,7 @@ class _EditPatientState extends State<EditPatient> {
|
||||
var decodedData = jsonDecode(body);
|
||||
AppUser u = AppUser.fromJson(decodedData as Map<String, dynamic>);
|
||||
setState(() {
|
||||
futureDocOfficeId = u.docOffice_ID;
|
||||
futureDocOfficeId = u.docOffice_id;
|
||||
//print(futureDocOfficeId);
|
||||
});
|
||||
} else {
|
||||
|
||||
@@ -4,7 +4,8 @@ import 'dart:convert';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:patient_manager/components/buildPatientList.dart';
|
||||
import 'package:patient_manager/components/myAppBar.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:supertokens_flutter/http.dart' as http;
|
||||
//import 'package:http/http.dart' as http;
|
||||
import 'package:patient_manager/components/mySearchInput.dart';
|
||||
import 'package:patient_manager/components/patManAppDrawer.dart';
|
||||
import 'package:patient_manager/env/env.dart';
|
||||
@@ -36,9 +37,9 @@ class _PatientManagerState extends State<PatientManager> {
|
||||
Future<List<Patient>> fetchPatients(String endpoint) async {
|
||||
//print("Patien manager page: $endpoint");
|
||||
final response = await http.get(Uri.parse(endpoint));
|
||||
// print("Here");
|
||||
// print("Body: ${response.body}");
|
||||
// print("Code: {response.statusCode}");
|
||||
print("Here");
|
||||
print("Body: ${response.body}");
|
||||
print("Code: ${response.statusCode}");
|
||||
errorCode = response.statusCode.toString();
|
||||
errorBody = response.body;
|
||||
|
||||
@@ -239,7 +240,10 @@ class _PatientManagerState extends State<PatientManager> {
|
||||
final screenHeight = MediaQuery.of(context).size.height;
|
||||
return Scaffold(
|
||||
appBar: const MyAppBar(barTitle: "Patient Manager"),
|
||||
drawer: PatManAppDrawer(userEmail: widget.userEmail),
|
||||
drawer: PatManAppDrawer(
|
||||
userEmail: widget.userEmail,
|
||||
logo: MzanziInnovationHub.of(context)!.theme.logoImage(),
|
||||
),
|
||||
//floatingActionButtonLocation: FloatingActionButtonLocation.,
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
label: Text(
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:google_nav_bar/google_nav_bar.dart';
|
||||
import 'package:patient_manager/components/myAppBar.dart';
|
||||
import 'package:patient_manager/components/profileOfficeUpdate.dart';
|
||||
import 'package:patient_manager/components/profileUserUpdate.dart';
|
||||
import 'package:patient_manager/main.dart';
|
||||
import 'package:patient_manager/objects/appUser.dart';
|
||||
|
||||
class ProfileUpdate extends StatefulWidget {
|
||||
@@ -20,7 +18,7 @@ class ProfileUpdate extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _ProfileUpdateState extends State<ProfileUpdate> {
|
||||
int _selectedIndex = 0;
|
||||
//int _selectedIndex = 0;
|
||||
late List<Widget> _widgetOptions;
|
||||
|
||||
@override
|
||||
@@ -42,34 +40,34 @@ class _ProfileUpdateState extends State<ProfileUpdate> {
|
||||
return Scaffold(
|
||||
appBar: const MyAppBar(barTitle: "Update Profile"),
|
||||
body: Center(
|
||||
child: _widgetOptions.elementAt(_selectedIndex),
|
||||
),
|
||||
bottomNavigationBar: GNav(
|
||||
//hoverColor: Colors.lightBlueAccent,
|
||||
color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||
iconSize: 35.0,
|
||||
activeColor: MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
||||
tabBackgroundColor:
|
||||
MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||
//gap: 20,
|
||||
//padding: EdgeInsets.all(15),
|
||||
tabs: const [
|
||||
GButton(
|
||||
icon: Icons.perm_identity,
|
||||
text: "User Profile",
|
||||
),
|
||||
GButton(
|
||||
icon: Icons.business,
|
||||
text: "Office Profile",
|
||||
),
|
||||
],
|
||||
selectedIndex: _selectedIndex,
|
||||
onTabChange: (index) {
|
||||
setState(() {
|
||||
_selectedIndex = index;
|
||||
});
|
||||
},
|
||||
child: _widgetOptions.elementAt(0),
|
||||
),
|
||||
// bottomNavigationBar: GNav(
|
||||
// //hoverColor: Colors.lightBlueAccent,
|
||||
// color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||
// iconSize: 35.0,
|
||||
// activeColor: MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
||||
// tabBackgroundColor:
|
||||
// MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||
// //gap: 20,
|
||||
// //padding: EdgeInsets.all(15),
|
||||
// tabs: const [
|
||||
// GButton(
|
||||
// icon: Icons.perm_identity,
|
||||
// text: "User Profile",
|
||||
// ),
|
||||
// GButton(
|
||||
// icon: Icons.business,
|
||||
// text: "Office Profile",
|
||||
// ),
|
||||
// ],
|
||||
// selectedIndex: _selectedIndex,
|
||||
// onTabChange: (index) {
|
||||
// setState(() {
|
||||
// _selectedIndex = index;
|
||||
// });
|
||||
// },
|
||||
// ),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,10 +40,9 @@ class _SignInState extends State<SignIn> {
|
||||
return AlertDialog(
|
||||
backgroundColor: _backgroundColor,
|
||||
content: Container(
|
||||
child: Center(
|
||||
child: MzanziInnovationHub.of(context)!
|
||||
.theme
|
||||
.loadingImage(), // Put your gif into the assets folder
|
||||
child: const Center(
|
||||
child:
|
||||
CircularProgressIndicator(), // Put your gif into the assets folder
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user