diff --git a/Frontend/patient_manager/lib/components/mihAppDrawer.dart b/Frontend/patient_manager/lib/components/mihAppDrawer.dart index e6a8a458..ff0deb7a 100644 --- a/Frontend/patient_manager/lib/components/mihAppDrawer.dart +++ b/Frontend/patient_manager/lib/components/mihAppDrawer.dart @@ -1,52 +1,23 @@ -import 'dart:convert'; - import 'package:flutter/material.dart'; -import 'package:gif/gif.dart'; -import 'package:patient_manager/env/env.dart'; import 'package:patient_manager/main.dart'; import 'package:patient_manager/objects/appUser.dart'; import 'package:supertokens_flutter/supertokens.dart'; -import 'package:supertokens_flutter/http.dart' as http; class MIHAppDrawer extends StatefulWidget { final AppUser signedInUser; + final ImageProvider? propicFile; //final AssetImage logo; const MIHAppDrawer({ super.key, required this.signedInUser, - //required this.logo, + required this.propicFile, }); @override State createState() => _MIHAppDrawerState(); } -class _MIHAppDrawerState extends State - with TickerProviderStateMixin { - late Future proPicUrl; - late final GifController _controller; - //String endpointUserData = "${AppEnviroment.baseApiUrl}/users/profile/"; - //late Future signedInUser; - //late Image logo; - - // Future getUserDetails() async { - // //print("pat man drawer: " + endpointUserData + widget.userEmail); - // var response = - // await http.get(Uri.parse(endpointUserData + widget.signedInUser)); - // // print(response.statusCode); - // //print(response.body); - // if (response.statusCode == 200) { - // //print("here"); - // String body = response.body; - // var decodedData = jsonDecode(body); - // AppUser u = AppUser.fromJson(decodedData as Map); - // //print(u.email); - // return u; - // } else { - // throw Exception("Error: GetUserData status code ${response.statusCode}"); - // } - // } - +class _MIHAppDrawerState extends State { Future signOut() async { await SuperTokens.signOut(completionHandler: (error) { // handle error if any @@ -54,39 +25,45 @@ class _MIHAppDrawerState extends State return true; } - Future getFileUrlApiCall(String filePath) async { - if (widget.signedInUser.pro_pic_path == "") { - return ""; - } else if (AppEnviroment.getEnv() == "Dev") { - return "${AppEnviroment.baseFileUrl}/mih/$filePath"; + Widget displayProPic() { + ImageProvider logoFrame = + MzanziInnovationHub.of(context)!.theme.logoFrame(); + if (widget.propicFile != null) { + return Stack( + alignment: Alignment.center, + fit: StackFit.loose, + children: [ + CircleAvatar( + backgroundColor: + MzanziInnovationHub.of(context)!.theme.primaryColor(), + backgroundImage: widget.propicFile, + //'https://media.licdn.com/dms/image/D4D03AQGd1-QhjtWWpA/profile-displayphoto-shrink_400_400/0/1671698053061?e=2147483647&v=beta&t=a3dJI5yxs5-KeXjj10LcNCFuC9IOfa8nNn3k_Qyr0CA'), + radius: 27, + ), + SizedBox( + width: 60, + child: Image(image: logoFrame), + ) + ], + ); } else { - var url = "${AppEnviroment.baseApiUrl}/minio/pull/file/$filePath/prod"; - var response = await http.get(Uri.parse(url)); - - if (response.statusCode == 200) { - String body = response.body; - var decodedData = jsonDecode(body); - - return decodedData['minioURL']; - } else { - throw Exception( - "Error: GetUserData status code ${response.statusCode}"); - } + return SizedBox( + width: 60, + child: Image(image: logoFrame), + ); } } @override void dispose() { - _controller.dispose(); super.dispose(); } @override void initState() { - setState(() { - proPicUrl = getFileUrlApiCall(widget.signedInUser.pro_pic_path); - }); - _controller = GifController(vsync: this); + // setState(() { + // proPicUrl = getFileUrlApiCall(widget.signedInUser.pro_pic_path); + // }); super.initState(); } @@ -96,8 +73,6 @@ class _MIHAppDrawerState extends State // MzanziInnovationHub.of(context)!.theme.logoImage().image, context); ImageProvider logoThemeSwitch = MzanziInnovationHub.of(context)!.theme.logoImage(); - ImageProvider logoFrame = - MzanziInnovationHub.of(context)!.theme.logoFrame(); return Drawer( //backgroundColor: MzanziInnovationHub.of(context)!.theme.primaryColor(), child: Stack(children: [ @@ -114,62 +89,7 @@ class _MIHAppDrawerState extends State crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [ - FutureBuilder( - future: proPicUrl, - builder: (BuildContext context, snapshot) { - if (snapshot.connectionState == ConnectionState.done) { - if (snapshot.hasData && snapshot.data != "") { - return Stack( - alignment: Alignment.center, - fit: StackFit.loose, - children: [ - CircleAvatar( - //backgroundColor: Colors.green, - backgroundImage: - NetworkImage(snapshot.requireData), - //'https://media.licdn.com/dms/image/D4D03AQGd1-QhjtWWpA/profile-displayphoto-shrink_400_400/0/1671698053061?e=2147483647&v=beta&t=a3dJI5yxs5-KeXjj10LcNCFuC9IOfa8nNn3k_Qyr0CA'), - radius: 27, - ), - SizedBox( - width: 60, - child: Image(image: logoFrame), - ) - ], - ); - } else { - return SizedBox( - width: 60, - child: Image(image: logoFrame), - ); - } - } else { - return Center( - child: Text( - '${snapshot.error} occurred', - style: const TextStyle(fontSize: 18), - ), - ); - } - }, - ), - // Stack( - // alignment: Alignment.center, - // fit: StackFit.loose, - // children: [ - // const CircleAvatar( - // backgroundColor: Colors.green, - // radius: 27, - // ), - // SizedBox( - // width: 60, - // child: Image(image: logoFrame), - // ) - // ], - // ), - // SizedBox( - // height: 60, - // child: Image(image: logoFrame), - // ), + displayProPic(), Text( "${widget.signedInUser.fname} ${widget.signedInUser.lname}", style: TextStyle( @@ -229,34 +149,6 @@ class _MIHAppDrawerState extends State .pushNamedAndRemoveUntil('/', (route) => false); }, ), - 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("MIHAppDrawer: ${signedInUser.runtimeType}"); - Navigator.of(context).popAndPushNamed('/user-profile', - arguments: widget.signedInUser); - }, - ), ListTile( title: Row( mainAxisSize: MainAxisSize.max, diff --git a/Frontend/patient_manager/lib/pages/profileUserUpdate.dart b/Frontend/patient_manager/lib/pages/profileUserUpdate.dart index 0cdc47e8..7ec228d7 100644 --- a/Frontend/patient_manager/lib/pages/profileUserUpdate.dart +++ b/Frontend/patient_manager/lib/pages/profileUserUpdate.dart @@ -11,17 +11,18 @@ import 'package:patient_manager/components/inputsAndButtons/mihTextInput.dart'; import 'package:patient_manager/components/inputsAndButtons/mihButton.dart'; import 'package:patient_manager/env/env.dart'; import 'package:patient_manager/main.dart'; -import 'package:patient_manager/objects/appUser.dart'; +import 'package:patient_manager/objects/arguments.dart'; import 'package:supertokens_flutter/http.dart' as http; import 'package:http/http.dart' as http2; import 'package:supertokens_flutter/supertokens.dart'; class ProfileUserUpdate extends StatefulWidget { - final AppUser signedInUser; - //final String userEmail; + final AppProfileUpdateArguments arguments; + // final AppUser signedInUser; + // final ImageProvider? propicFile; const ProfileUserUpdate({ super.key, - required this.signedInUser, + required this.arguments, }); @override @@ -35,7 +36,7 @@ class _ProfileUserUpdateState extends State { final lnameController = TextEditingController(); late PlatformFile proPic; - late Future proPicUrl; + late ImageProvider? propicPreview; late bool businessUser; final FocusNode _focusNode = FocusNode(); @@ -44,7 +45,8 @@ class _ProfileUserUpdateState extends State { Future deleteFileApiCall(String filename) async { // delete file from minio var fname = filename.replaceAll(RegExp(r' '), '-'); - var filePath = "${widget.signedInUser.app_id}/profile_files/$fname"; + var filePath = + "${widget.arguments.signedInUser.app_id}/profile_files/$fname"; var response = await http.delete( Uri.parse("${AppEnviroment.baseApiUrl}/minio/delete/file/"), headers: { @@ -62,7 +64,7 @@ class _ProfileUserUpdateState extends State { } Future getFileUrlApiCall(String filePath) async { - if (widget.signedInUser.pro_pic_path == "") { + if (widget.arguments.signedInUser.pro_pic_path == "") { return ""; } else if (AppEnviroment.getEnv() == "Dev") { return "${AppEnviroment.baseFileUrl}/mih/$filePath"; @@ -98,7 +100,7 @@ class _ProfileUserUpdateState extends State { request.headers['accept'] = 'application/json'; request.headers['Authorization'] = 'Bearer $token'; request.headers['Content-Type'] = 'multipart/form-data'; - request.fields['app_id'] = widget.signedInUser.app_id; + request.fields['app_id'] = widget.arguments.signedInUser.app_id; request.fields['folder'] = "profile_files"; request.files.add(await http2.MultipartFile.fromBytes('file', file.bytes!, filename: file.name.replaceAll(RegExp(r' '), '-'))); @@ -128,7 +130,8 @@ class _ProfileUserUpdateState extends State { Future updateUserApiCall() async { var fname = proPicController.text.replaceAll(RegExp(r' '), '-'); - var filePath = "${widget.signedInUser.app_id}/profile_files/$fname"; + var filePath = + "${widget.arguments.signedInUser.app_id}/profile_files/$fname"; var profileType; if (businessUser) { profileType = "business"; @@ -144,7 +147,7 @@ class _ProfileUserUpdateState extends State { "Content-Type": "application/json; charset=UTF-8" }, body: jsonEncode({ - "idusers": widget.signedInUser.idUser, + "idusers": widget.arguments.signedInUser.idUser, "username": usernameController.text, "fnam": fnameController.text, "lname": lnameController.text, @@ -156,9 +159,9 @@ class _ProfileUserUpdateState extends State { //print(response.statusCode); if (response.statusCode == 200) { Navigator.of(context) - .popAndPushNamed('/', arguments: widget.signedInUser); + .popAndPushNamed('/', arguments: widget.arguments.signedInUser); String message = - "${widget.signedInUser.email}'s information has been updated successfully!"; + "${widget.arguments.signedInUser.email}'s information has been updated successfully!"; successPopUp(message); } else { internetConnectionPopUp(); @@ -167,7 +170,7 @@ class _ProfileUserUpdateState extends State { } bool isBusinessUser() { - if (widget.signedInUser.type == "personal") { + if (widget.arguments.signedInUser.type == "personal") { return false; } else { return true; @@ -225,6 +228,35 @@ class _ProfileUserUpdateState extends State { } } + Widget displayProPic() { + ImageProvider logoFrame = + MzanziInnovationHub.of(context)!.theme.altLogoFrame(); + if (widget.arguments.propicFile != null) { + return Stack( + alignment: Alignment.center, + fit: StackFit.loose, + children: [ + CircleAvatar( + backgroundColor: + MzanziInnovationHub.of(context)!.theme.primaryColor(), + backgroundImage: propicPreview, + //'https://media.licdn.com/dms/image/D4D03AQGd1-QhjtWWpA/profile-displayphoto-shrink_400_400/0/1671698053061?e=2147483647&v=beta&t=a3dJI5yxs5-KeXjj10LcNCFuC9IOfa8nNn3k_Qyr0CA'), + radius: 50, + ), + SizedBox( + width: 110, + child: Image(image: logoFrame), + ) + ], + ); + } else { + return SizedBox( + width: 60, + child: Image(image: logoFrame), + ); + } + } + @override void dispose() { proPicController.dispose(); @@ -238,16 +270,16 @@ class _ProfileUserUpdateState extends State { @override void initState() { var proPicName = ""; - if (widget.signedInUser.pro_pic_path.isNotEmpty) { - proPicName = widget.signedInUser.pro_pic_path.split("/").last; + if (widget.arguments.signedInUser.pro_pic_path.isNotEmpty) { + proPicName = widget.arguments.signedInUser.pro_pic_path.split("/").last; } setState(() { - proPicUrl = getFileUrlApiCall(widget.signedInUser.pro_pic_path); + propicPreview = widget.arguments.propicFile; oldProPicName = proPicName; proPicController.text = proPicName; - fnameController.text = widget.signedInUser.fname; - lnameController.text = widget.signedInUser.lname; - usernameController.text = widget.signedInUser.username; + fnameController.text = widget.arguments.signedInUser.fname; + lnameController.text = widget.arguments.signedInUser.lname; + usernameController.text = widget.arguments.signedInUser.username; businessUser = isBusinessUser(); }); @@ -287,51 +319,7 @@ class _ProfileUserUpdateState extends State { ), ), const SizedBox(height: 25.0), - FutureBuilder( - future: proPicUrl, - builder: (BuildContext context, snapshot) { - if (snapshot.connectionState == - ConnectionState.done) { - if (snapshot.hasData && snapshot.data != "") { - return Stack( - alignment: Alignment.center, - fit: StackFit.loose, - children: [ - CircleAvatar( - //backgroundColor: Colors.green, - backgroundImage: - NetworkImage(snapshot.requireData), - //'https://media.licdn.com/dms/image/D4D03AQGd1-QhjtWWpA/profile-displayphoto-shrink_400_400/0/1671698053061?e=2147483647&v=beta&t=a3dJI5yxs5-KeXjj10LcNCFuC9IOfa8nNn3k_Qyr0CA'), - radius: 50, - ), - SizedBox( - width: 110, - child: Image( - image: - MzanziInnovationHub.of(context)! - .theme - .altLogoFrame()), - ) - ], - ); - } else { - return SizedBox( - width: 110, - child: Image( - image: MzanziInnovationHub.of(context)! - .theme - .altLogoFrame())); - } - } else { - return Center( - child: Text( - '${snapshot.error} occurred', - style: const TextStyle(fontSize: 18), - ), - ); - } - }, - ), + displayProPic(), const SizedBox(height: 25.0), MIHFileField( controller: proPicController, @@ -342,12 +330,13 @@ class _ProfileUserUpdateState extends State { FilePickerResult? result = await FilePicker.platform.pickFiles( type: FileType.custom, - allowedExtensions: ['jpg', 'png', 'pdf'], + allowedExtensions: ['jpg', 'png'], ); if (result == null) return; final selectedFile = result.files.first; setState(() { proPic = selectedFile; + propicPreview = MemoryImage(proPic.bytes!); }); setState(() {