48 lines
1.6 KiB
Dart
48 lines
1.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 UserIndiProfileImageController extends GetxController {
|
|
RxString usserprofilePicPath = "".obs;
|
|
|
|
void getImage(ImageSource imgSource) async {
|
|
final ImagePicker picker = ImagePicker();
|
|
print('profilePicPath $usserprofilePicPath');
|
|
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) {
|
|
usserprofilePicPath.value = croppedImg.path;
|
|
}
|
|
}
|
|
}
|
|
}
|