37 lines
1011 B
Dart
37 lines
1011 B
Dart
|
|
import 'package:image_cropper/image_cropper.dart';
|
||
|
|
import 'package:image_picker/image_picker.dart';
|
||
|
|
|
||
|
|
class ImagePickerMethod {
|
||
|
|
Future<String> getImage(ImageSource imgSource) async {
|
||
|
|
final ImagePicker picker = ImagePicker();
|
||
|
|
|
||
|
|
final XFile? pickedImg = await picker.pickImage(source: imgSource);
|
||
|
|
if (pickedImg != null) {
|
||
|
|
final croppedImg = await ImageCropper().cropImage(
|
||
|
|
sourcePath: pickedImg.path,
|
||
|
|
aspectRatio: const CropAspectRatio(ratioX: 1, ratioY: 1),
|
||
|
|
compressFormat: ImageCompressFormat.jpg,
|
||
|
|
maxHeight: 512,
|
||
|
|
maxWidth: 512,
|
||
|
|
uiSettings: [
|
||
|
|
IOSUiSettings(
|
||
|
|
rotateButtonsHidden: true,
|
||
|
|
rotateClockwiseButtonHidden: true,
|
||
|
|
)
|
||
|
|
],
|
||
|
|
compressQuality: 100,
|
||
|
|
aspectRatioPresets: [
|
||
|
|
CropAspectRatioPreset.square,
|
||
|
|
],
|
||
|
|
);
|
||
|
|
if (croppedImg != null) {
|
||
|
|
return croppedImg.path;
|
||
|
|
} else {
|
||
|
|
return "";
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
return "";
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|