From c616dedfb276ab44ecf8bde51ecb02488e4624d1 Mon Sep 17 00:00:00 2001 From: yaso Date: Wed, 30 Oct 2024 12:39:33 +0200 Subject: [PATCH] add new MIH_profilePicture to mzansi profile. --- .../mzansi_profile/profile_user_update.dart | 77 +++++-------------- 1 file changed, 20 insertions(+), 57 deletions(-) diff --git a/Frontend/patient_manager/lib/mih_packages/mzansi_profile/profile_user_update.dart b/Frontend/patient_manager/lib/mih_packages/mzansi_profile/profile_user_update.dart index f1c4d412..8737136f 100644 --- a/Frontend/patient_manager/lib/mih_packages/mzansi_profile/profile_user_update.dart +++ b/Frontend/patient_manager/lib/mih_packages/mzansi_profile/profile_user_update.dart @@ -13,6 +13,7 @@ import 'package:patient_manager/mih_components/mih_pop_up_messages/mih_error_mes import 'package:patient_manager/mih_components/mih_pop_up_messages/mih_success_message.dart'; import 'package:patient_manager/mih_components/mih_inputs_and_buttons/mih_text_input.dart'; import 'package:patient_manager/mih_components/mih_inputs_and_buttons/mih_button.dart'; +import 'package:patient_manager/mih_components/mih_profile_picture.dart'; import 'package:patient_manager/mih_env/env.dart'; import 'package:patient_manager/main.dart'; import 'package:patient_manager/mih_objects/arguments.dart'; @@ -39,7 +40,7 @@ class _ProfileUserUpdateState extends State { final fnameController = TextEditingController(); final lnameController = TextEditingController(); - late PlatformFile proPic; + PlatformFile? proPic; late ImageProvider? propicPreview; late bool businessUser; final FocusNode _focusNode = FocusNode(); @@ -88,7 +89,8 @@ class _ProfileUserUpdateState extends State { } } - Future uploadSelectedFile(PlatformFile file) async { + Future uploadSelectedFile(PlatformFile? file) async { + //print("MIH Profile Picture: $file"); //var strem = new http.ByteStream.fromBytes(file.bytes.) //start loading circle showDialog( @@ -106,7 +108,7 @@ class _ProfileUserUpdateState extends State { request.headers['Content-Type'] = 'multipart/form-data'; request.fields['app_id'] = widget.arguments.signedInUser.app_id; request.fields['folder'] = "profile_files"; - request.files.add(await http2.MultipartFile.fromBytes('file', file.bytes!, + request.files.add(await http2.MultipartFile.fromBytes('file', file!.bytes!, filename: file.name.replaceAll(RegExp(r' '), '-'))); var response1 = await request.send(); if (response1.statusCode == 200) { @@ -232,58 +234,6 @@ 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: 70, - ), - SizedBox( - width: 155, - child: Image(image: logoFrame), - ), - Positioned( - bottom: 0, - right: 0, - child: IconButton.filled( - onPressed: () async { - FilePickerResult? result = await FilePicker.platform.pickFiles( - type: FileType.custom, - allowedExtensions: ['jpg', 'png'], - ); - if (result == null) return; - final selectedFile = result.files.first; - setState(() { - proPic = selectedFile; - propicPreview = MemoryImage(proPic.bytes!); - }); - - setState(() { - proPicController.text = selectedFile.name; - }); - }, - icon: const Icon(Icons.edit), - ), - ), - ], - ); - } else { - return SizedBox( - width: 155, - child: Image(image: logoFrame), - ); - } - } - MIHAction getActionButton() { return MIHAction( icon: const Icon(Icons.arrow_back), @@ -317,7 +267,20 @@ class _ProfileUserUpdateState extends State { return MIHBody( borderOn: false, bodyItems: [ - displayProPic(), + //displayProPic(), + MIHProfilePicture( + profilePictureFile: widget.arguments.propicFile, + proPicController: proPicController, + proPic: proPic, + width: 155, + radius: 70, + editable: true, + onChange: (newProPic) { + setState(() { + proPic = newProPic; + }); + }, + ), const SizedBox(height: 25.0), Visibility( visible: false, @@ -335,7 +298,7 @@ class _ProfileUserUpdateState extends State { final selectedFile = result.files.first; setState(() { proPic = selectedFile; - propicPreview = MemoryImage(proPic.bytes!); + propicPreview = MemoryImage(proPic!.bytes!); }); setState(() {