Files
Regroup/lib/Common/controller/profileimagecontroller.dart

126 lines
4.6 KiB
Dart

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:image_picker/image_picker.dart';
import 'package:image_cropper/image_cropper.dart';
class ProfileImageController extends GetxController {
RxString profilePicPath = "".obs;
//RxString fileNameFromPath = "".obs;
// void getImage(ImageSource imgSource) async {
// final ImagePicker picker = ImagePicker();
// print('profilePicPath $profilePicPath');
// final XFile? pickedImg = await picker.pickImage(source: imgSource);
// if (pickedImg != null) {
// final CroppedFile? croppedImg = await ImageCropper().cropImage(
// sourcePath: pickedImg.path,
// aspectRatio: const CropAspectRatio(ratioX: 1, ratioY: 1),
// compressFormat: ImageCompressFormat.jpg,
// maxHeight: 512,
// maxWidth: 512,
// compressQuality: 100,
// cropStyle: CropStyle.circle,
// aspectRatioPresets: [
// CropAspectRatioPreset.square,
// ],
// uiSettings: [
// AndroidUiSettings(
// toolbarTitle: "Crop Image",
// toolbarColor: Get.theme.appBarTheme.backgroundColor,
// // toolbarWidgetColor: ColorConstants.kWhite,
// backgroundColor: Colors.black,
// activeControlsWidgetColor: Colors.red,
// // initAspectRatio: CropAspectRatioPreset.original,
// cropFrameColor: Colors.white,
// lockAspectRatio: false,
// ),
// IOSUiSettings(
// title: 'Crop Image',
// ),
// ]);
// if (croppedImg != null) {
// // profilPic = croppedImg.path;
// profilePicPath.value = croppedImg.path;
// // Get.back();
// // fileNameFromPath.value = extractFileName(croppedImg.path);
// }
// }
// // if (pickedImg != null) {
// // final CroppedFile? croppedImg = await ImageCropper().cropImage(
// // sourcePath: pickedImg.path,
// // aspectRatio: const CropAspectRatio(ratioX: 1, ratioY: 1),
// // compressFormat: ImageCompressFormat.jpg,
// // maxHeight: 512,
// // maxWidth: 512,
// // compressQuality: 100,
// // cropStyle: CropStyle.circle,
// // aspectRatioPresets: [
// // CropAspectRatioPreset.square,
// // ],
// // uiSettings: [
// // AndroidUiSettings(
// // toolbarTitle: "Crop Image",
// // toolbarColor: Get.theme.appBarTheme.backgroundColor,
// // // toolbarWidgetColor: ColorConstants.kWhite,
// // backgroundColor: Colors.black,
// // activeControlsWidgetColor: Colors.red,
// // // initAspectRatio: CropAspectRatioPreset.original,
// // cropFrameColor: Colors.white,
// // lockAspectRatio: false,
// // ),
// // IOSUiSettings(
// // title: 'Crop Image',
// // ),
// // ]);
// // if (croppedImg != null) {
// // // profilPic = croppedImg.path;
// // profilePicPath.value = croppedImg.path;
// // // Get.back();
// // // fileNameFromPath.value = extractFileName(croppedImg.path);
// // }
// // }
// }
void getImage(ImageSource imgSource) async {
final ImagePicker picker = ImagePicker();
print('profilePicPath $profilePicPath');
final XFile? pickedImg = await picker.pickImage(source: imgSource);
if (pickedImg != null) {
final CroppedFile? croppedImg = await ImageCropper().cropImage(
sourcePath: pickedImg.path,
aspectRatio: const CropAspectRatio(ratioX: 1, ratioY: 1),
compressFormat: ImageCompressFormat.jpg,
maxHeight: 512,
maxWidth: 512,
compressQuality: 100,
cropStyle: CropStyle.circle,
aspectRatioPresets: [
CropAspectRatioPreset.square,
],
uiSettings: [
AndroidUiSettings(
toolbarTitle: "Crop Image",
toolbarColor: Get.theme.appBarTheme.backgroundColor,
backgroundColor: Colors.black,
activeControlsWidgetColor: Colors.red,
cropFrameColor: Colors.white,
cropGridColor: Colors.white, // Ensure this matches the theme
cropGridColumnCount: 2, // Add to make the grid lines prominent
cropGridRowCount: 2, // Add to make the grid lines prominent
lockAspectRatio: true, // Ensure the aspect ratio is locked
),
IOSUiSettings(
title: 'Crop Image',
),
],
);
if (croppedImg != null) {
profilePicPath.value = croppedImg.path;
}
}
}
}