|
|
|
|
@ -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",
|
|
|
|
|
|