diff --git a/Frontend/patient_manager/lib/pages/profileUserUpdate.dart b/Frontend/patient_manager/lib/pages/profileUserUpdate.dart index f5b70e44..51eb8b13 100644 --- a/Frontend/patient_manager/lib/pages/profileUserUpdate.dart +++ b/Frontend/patient_manager/lib/pages/profileUserUpdate.dart @@ -44,6 +44,28 @@ class _ProfileUserUpdateState extends State final FocusNode _focusNode = FocusNode(); late final GifController _controller; + late String oldProPicName; + + 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 response = await http.delete( + Uri.parse("${AppEnviroment.baseApiUrl}/minio/delete/file/"), + headers: { + "Content-Type": "application/json; charset=UTF-8" + }, + body: jsonEncode({"file_path": filePath}), + ); + //print("Here4"); + //print(response.statusCode); + if (response.statusCode == 200) { + //SQL delete + } else { + internetConnectionPopUp(); + } + } + Future getFileUrlApiCall(String filePath) async { if (widget.signedInUser.pro_pic_path == "") { return ""; @@ -87,10 +109,8 @@ class _ProfileUserUpdateState extends State filename: file.name.replaceAll(RegExp(r' '), '-'))); var response1 = await request.send(); if (response1.statusCode == 200) { - setState(() { - //proPicController.clear(); - //futueFiles = fetchFiles(); - }); + deleteFileApiCall(oldProPicName); + // end loading circle //Navigator.of(context).pop(); // String message = @@ -196,7 +216,9 @@ class _ProfileUserUpdateState extends State Future submitForm() async { if (isFieldsFilled()) { - await uploadSelectedFile(proPic); + if (oldProPicName != proPicController.text) { + await uploadSelectedFile(proPic); + } await updateUserApiCall(); } else { showDialog( @@ -228,6 +250,7 @@ class _ProfileUserUpdateState extends State _controller = GifController(vsync: this); setState(() { proPicUrl = getFileUrlApiCall(widget.signedInUser.pro_pic_path); + oldProPicName = proPicName; proPicController.text = proPicName; fnameController.text = widget.signedInUser.fname; lnameController.text = widget.signedInUser.lname; @@ -313,7 +336,7 @@ class _ProfileUserUpdateState extends State MIHFileField( controller: proPicController, hintText: "Profile Picture", - editable: true, + editable: false, required: false, onPressed: () async { FilePickerResult? result =