diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 92e2d53..9054845 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -1,7 +1,9 @@ + > ", response.toString()); + dp("============Error Response", err.response); if (err.response != null) { ServerResponse response = ServerResponse.init(); + ApiUtils.parseError(response, err.response!); + pe("Response_ERROR =>> ", response.toString()); + } else { + pe("DIO_ERROR =>> ", err.message); + + pe("ERROR_TYPE =>> ", err.type.toString()); + + pe("STACKTRACE =>> ", err.error.toString()); } + return super.onError(err, handler); } } diff --git a/lib/app/modules/user_profile/controllers/user_profile_controller.dart b/lib/app/modules/user_profile/controllers/user_profile_controller.dart index bac5dce..243cfce 100644 --- a/lib/app/modules/user_profile/controllers/user_profile_controller.dart +++ b/lib/app/modules/user_profile/controllers/user_profile_controller.dart @@ -5,8 +5,8 @@ import 'package:flutter/services.dart'; import 'package:get/get.dart'; import 'package:image/image.dart' as img; import 'package:share_plus/share_plus.dart'; -// import 'package:image_picker/image_picker.dart'; - +import 'package:image_picker/image_picker.dart'; +import 'package:image_gallery_saver_plus/image_gallery_saver_plus.dart'; import '../../../core/config/server_response.dart'; import '../../../core/constants/app_contants.dart'; @@ -36,7 +36,7 @@ class UserProfileController extends GetxController { static RxString cmpCustImage = "".obs; static RxString selectedLocale = "en".obs; - // ImagePicker imagePicker = ImagePicker(); + ImagePicker imagePicker = ImagePicker(); late InputField firstNameField; late InputField depositAccountField; @@ -72,25 +72,51 @@ class UserProfileController extends GetxController { } } + // void uploadUserProfilePicture() async { + // if (profilePic == null || profilePic!.isEmpty) { + // Toasty.error("Please select an image to upload."); + // return; + // } + // + // hideKeyBoard(); + // UploadUserProfileModel request = UploadUserProfileModel( + // cmpCustcode: SessionCache.instance.userInfo.cmpCustcode, + // porOrgacode: SessionCache.instance.userInfo.porOrgacode, + // cmpCustImage: "", + // ); + // + // ServerResponse response = await repository.uploadUserProfilePicture(request); + // if (response.isError) { + // Toasty.error(response.errorMsg); + // return; + // } + // cmpCustImage.value = profilePic.value; + // Toasty.success("Profile picture updated successfully."); + // } void uploadUserProfilePicture() async { - if (profilePic == null || profilePic!.isEmpty) { + if (profilePic.value.isEmpty) { Toasty.error("Please select an image to upload."); return; } hideKeyBoard(); + UploadUserProfileModel request = UploadUserProfileModel( cmpCustcode: SessionCache.instance.userInfo.cmpCustcode, porOrgacode: SessionCache.instance.userInfo.porOrgacode, - cmpCustImage: "", + cmpCustImage: profilePic.value, ); - ServerResponse response = await repository.uploadUserProfilePicture(request); + ServerResponse response = + await repository.uploadUserProfilePicture(request); + if (response.isError) { Toasty.error(response.errorMsg); return; } + cmpCustImage.value = profilePic.value; + Toasty.success("Profile picture updated successfully."); } @@ -180,9 +206,9 @@ class UserProfileController extends GetxController { // img.Image resizedImage = img.copyResize(image, width: 800); // Adjust the width as needed // // // Encode the resized image to base64 - // profilePic = base64Encode(img.encodeJpg(resizedImage)); + // profilePic = base64Encode(img.encodeJpg(resizedImage)) as RxString; // - // AppStorage.putString("ProfileImage", profilePic!); + // AppStorage.putString("ProfileImage", profilePic as String); // uploadUserProfilePicture(); // update(); // } else { @@ -191,6 +217,69 @@ class UserProfileController extends GetxController { // } // } + void updateProfilePic({required bool fromCamera}) async { + try { + XFile? imageResult; + + if (fromCamera) { + imageResult = await imagePicker.pickImage( + source: ImageSource.camera, + imageQuality: 70, + ); + } else { + imageResult = await imagePicker.pickImage( + source: ImageSource.gallery, + imageQuality: 70, + ); + } + + Get.back(); + + if (imageResult == null) { + return; + } + + // Read image bytes + Uint8List imageBytes = await imageResult.readAsBytes(); + + // Decode image + img.Image? image = img.decodeImage(imageBytes); + + if (image == null) { + Toasty.error("Failed to decode image."); + return; + } + + // Resize image + img.Image resizedImage = img.copyResize( + image, + width: 800, + ); + + // Convert to base64 + String base64Image = base64Encode( + img.encodeJpg(resizedImage), + ); + + // Update RxString properly + profilePic.value = base64Image; + + // Save locally + await AppStorage.putString( + SessionCache.instance.userInfo.cmpUserId, + base64Image, + ); + + // Upload API + uploadUserProfilePicture(); + + update(); + } catch (e) { + dp("Image Error", e.toString()); + Toasty.error("Failed to select image"); + } + } + void removeProfilePic() { AppStorage.delete(SessionCache.instance.userInfo.cmpUserId); profilePic.value = ''; @@ -198,13 +287,21 @@ class UserProfileController extends GetxController { Get.back(); } + // void loadProfilePic() async { + // profilePic.value = await AppStorage.getString(SessionCache.instance.userInfo.cmpUserId); + // update(); + // String? pic = await AppStorage.getString(SessionCache.instance.userInfo.cmpUserId); + // profilePic.value = pic; + // } void loadProfilePic() async { - // profilePic.value = await AppStorage.getString(SessionCache.instance.userInfo.cmpUserId); - // update(); - String? pic = await AppStorage.getString(SessionCache.instance.userInfo.cmpUserId); - profilePic.value = pic; - } + String? pic = await AppStorage.getString( + SessionCache.instance.userInfo.cmpUserId, + ); + + profilePic.value = pic ?? ''; + update(); + } void updateName() { Get.defaultDialog( title: "Update user name", diff --git a/lib/app/modules/user_profile/views/profile_details_view.dart b/lib/app/modules/user_profile/views/profile_details_view.dart index 315a757..31e05a9 100644 --- a/lib/app/modules/user_profile/views/profile_details_view.dart +++ b/lib/app/modules/user_profile/views/profile_details_view.dart @@ -127,10 +127,10 @@ class ProfileDetailsTile extends StatelessWidget { style: context.textTheme.bodyMedium!.copyWith(fontSize: 10, fontWeight: FontWeight.w400), ), const SizedBox(height: 4), - // Text( - // // subtitle, - // style: context.textTheme.bodyMedium!.copyWith(fontSize: 15, fontWeight: FontWeight.w400), - // ), + Text( + subtitle, + style: context.textTheme.bodyMedium!.copyWith(fontSize: 15, fontWeight: FontWeight.w400), + ), const SizedBox(height: 8), widget ?? const SizedBox(), widget == null diff --git a/lib/app/modules/user_profile/views/user_profile_view.dart b/lib/app/modules/user_profile/views/user_profile_view.dart index 93c8ddf..ecb8a4c 100644 --- a/lib/app/modules/user_profile/views/user_profile_view.dart +++ b/lib/app/modules/user_profile/views/user_profile_view.dart @@ -225,11 +225,11 @@ showProfileUpdateSheet() { const SizedBox(height: 20), btnTileB("Choose From Photos", () { dp("", ""); - // controller.updateProfilePic(fromCamera: false); + controller.updateProfilePic(fromCamera: false); }), btnTileB("Take a photo", () { dp("", ""); - // controller.updateProfilePic(fromCamera: true); + controller.updateProfilePic(fromCamera: true); }), btnTileB("Remove Profile Picture", () { dp("", ""); diff --git a/pubspec.yaml b/pubspec.yaml index 7cb83f9..daed5bd 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -69,11 +69,11 @@ dependencies: buttons_tabbar: 1.3.8 google_maps_flutter: 2.14.0 path_provider: 2.1.3 - # image_picker: ^1.2.1 + image_picker: ^1.2.1 qr_flutter: ^4.1.0 mobile_scanner: ^6.0.10 screenshot: 3.0.0 - # image_gallery_saver: 2.0.1 + image_gallery_saver_plus: ^4.0.1 flutter_keyboard_visibility: 6.0.0 # qr_code_scanner: # git: