52 lines
1.8 KiB
Dart
52 lines
1.8 KiB
Dart
import 'package:get/get.dart';
|
|
import 'package:gsp_app/views/theme.dart';
|
|
import 'package:image_picker/image_picker.dart';
|
|
import 'package:image_cropper/image_cropper.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
class SelectProfilePictureController extends GetxController {
|
|
RxString profilePicPath = "".obs;
|
|
// RxBool showSelectedProfilePic = false.obs;
|
|
|
|
void selectImg(ImageSource imgSource) async {
|
|
final ImagePicker picker = ImagePicker();
|
|
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,
|
|
// CropAspectRatioPreset.ratio3x2,
|
|
// CropAspectRatioPreset.original,
|
|
// CropAspectRatioPreset.ratio4x3,
|
|
// CropAspectRatioPreset.ratio16x9
|
|
],
|
|
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) {
|
|
profilePicPath.value = croppedImg.path;
|
|
Get.back();
|
|
}
|
|
}
|
|
}
|
|
}
|