Merge pull request 'upload-profile-image-issues-fixes' (#9) from PROFILE_UPLOAD-ISSUES-FIXES into pre_developmnet_branch

Reviewed-on: https://ct.mfsys.com.pk/UCO-Projects/uco-mobile-poc/pulls/9
QR_Issues_fixes_sawara
Waqas Khurshid 16 hours ago
commit 7abfb2b568

@ -1,7 +1,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> <manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
<application <application
android:label="uco_mobile_poc" android:label="uco_mobile_poc"
android:name="${applicationName}" android:name="${applicationName}"
android:requestLegacyExternalStorage="true"
android:icon="@mipmap/ic_launcher"> android:icon="@mipmap/ic_launcher">
<activity <activity
android:name=".MainActivity" android:name=".MainActivity"

@ -35,18 +35,23 @@ class Logging extends Interceptor {
@override @override
void onError(DioError err, ErrorInterceptorHandler handler) { void onError(DioError err, ErrorInterceptorHandler handler) {
hideLoader(); hideLoader();
dp("============Error Response", err.response);
ServerResponse response = ServerResponse.init();
ApiUtils.parseError(response, err.response!);
pe("Response_ERROR =>> ", response.toString()); dp("============Error Response", err.response);
if (err.response != null) { if (err.response != null) {
ServerResponse response = ServerResponse.init(); ServerResponse response = ServerResponse.init();
ApiUtils.parseError(response, err.response!); ApiUtils.parseError(response, err.response!);
pe("Response_ERROR =>> ", response.toString()); 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); return super.onError(err, handler);
} }
} }

@ -5,8 +5,8 @@ import 'package:flutter/services.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:image/image.dart' as img; import 'package:image/image.dart' as img;
import 'package:share_plus/share_plus.dart'; 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/config/server_response.dart';
import '../../../core/constants/app_contants.dart'; import '../../../core/constants/app_contants.dart';
@ -36,7 +36,7 @@ class UserProfileController extends GetxController {
static RxString cmpCustImage = "".obs; static RxString cmpCustImage = "".obs;
static RxString selectedLocale = "en".obs; static RxString selectedLocale = "en".obs;
// ImagePicker imagePicker = ImagePicker(); ImagePicker imagePicker = ImagePicker();
late InputField firstNameField; late InputField firstNameField;
late InputField depositAccountField; 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 { void uploadUserProfilePicture() async {
if (profilePic == null || profilePic!.isEmpty) { if (profilePic.value.isEmpty) {
Toasty.error("Please select an image to upload."); Toasty.error("Please select an image to upload.");
return; return;
} }
hideKeyBoard(); hideKeyBoard();
UploadUserProfileModel request = UploadUserProfileModel( UploadUserProfileModel request = UploadUserProfileModel(
cmpCustcode: SessionCache.instance.userInfo.cmpCustcode, cmpCustcode: SessionCache.instance.userInfo.cmpCustcode,
porOrgacode: SessionCache.instance.userInfo.porOrgacode, porOrgacode: SessionCache.instance.userInfo.porOrgacode,
cmpCustImage: "", cmpCustImage: profilePic.value,
); );
ServerResponse response = await repository.uploadUserProfilePicture(request); ServerResponse response =
await repository.uploadUserProfilePicture(request);
if (response.isError) { if (response.isError) {
Toasty.error(response.errorMsg); Toasty.error(response.errorMsg);
return; return;
} }
cmpCustImage.value = profilePic.value; cmpCustImage.value = profilePic.value;
Toasty.success("Profile picture updated successfully."); 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 // img.Image resizedImage = img.copyResize(image, width: 800); // Adjust the width as needed
// //
// // Encode the resized image to base64 // // 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(); // uploadUserProfilePicture();
// update(); // update();
// } else { // } 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() { void removeProfilePic() {
AppStorage.delete(SessionCache.instance.userInfo.cmpUserId); AppStorage.delete(SessionCache.instance.userInfo.cmpUserId);
profilePic.value = ''; profilePic.value = '';
@ -198,13 +287,21 @@ class UserProfileController extends GetxController {
Get.back(); 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 { void loadProfilePic() async {
// profilePic.value = await AppStorage.getString(SessionCache.instance.userInfo.cmpUserId); String? pic = await AppStorage.getString(
// update(); SessionCache.instance.userInfo.cmpUserId,
String? pic = await AppStorage.getString(SessionCache.instance.userInfo.cmpUserId); );
profilePic.value = pic;
} profilePic.value = pic ?? '';
update();
}
void updateName() { void updateName() {
Get.defaultDialog( Get.defaultDialog(
title: "Update user name", title: "Update user name",

@ -127,10 +127,10 @@ class ProfileDetailsTile extends StatelessWidget {
style: context.textTheme.bodyMedium!.copyWith(fontSize: 10, fontWeight: FontWeight.w400), style: context.textTheme.bodyMedium!.copyWith(fontSize: 10, fontWeight: FontWeight.w400),
), ),
const SizedBox(height: 4), const SizedBox(height: 4),
// Text( Text(
// // subtitle, subtitle,
// style: context.textTheme.bodyMedium!.copyWith(fontSize: 15, fontWeight: FontWeight.w400), style: context.textTheme.bodyMedium!.copyWith(fontSize: 15, fontWeight: FontWeight.w400),
// ), ),
const SizedBox(height: 8), const SizedBox(height: 8),
widget ?? const SizedBox(), widget ?? const SizedBox(),
widget == null widget == null

@ -225,11 +225,11 @@ showProfileUpdateSheet() {
const SizedBox(height: 20), const SizedBox(height: 20),
btnTileB("Choose From Photos", () { btnTileB("Choose From Photos", () {
dp("", ""); dp("", "");
// controller.updateProfilePic(fromCamera: false); controller.updateProfilePic(fromCamera: false);
}), }),
btnTileB("Take a photo", () { btnTileB("Take a photo", () {
dp("", ""); dp("", "");
// controller.updateProfilePic(fromCamera: true); controller.updateProfilePic(fromCamera: true);
}), }),
btnTileB("Remove Profile Picture", () { btnTileB("Remove Profile Picture", () {
dp("", ""); dp("", "");

@ -69,11 +69,11 @@ dependencies:
buttons_tabbar: 1.3.8 buttons_tabbar: 1.3.8
google_maps_flutter: 2.14.0 google_maps_flutter: 2.14.0
path_provider: 2.1.3 path_provider: 2.1.3
# image_picker: ^1.2.1 image_picker: ^1.2.1
qr_flutter: ^4.1.0 qr_flutter: ^4.1.0
mobile_scanner: ^6.0.10 mobile_scanner: ^6.0.10
screenshot: 3.0.0 screenshot: 3.0.0
# image_gallery_saver: 2.0.1 image_gallery_saver_plus: ^4.0.1
flutter_keyboard_visibility: 6.0.0 flutter_keyboard_visibility: 6.0.0
# qr_code_scanner: # qr_code_scanner:
# git: # git:

Loading…
Cancel
Save