openCropper method

Future<LikkEntity?> openCropper(
  1. BuildContext context,
  2. LikkEntity entity
)

Open camera from GalleryView

Implementation

Future<LikkEntity?> openCropper(
    BuildContext context, LikkEntity entity) async {
  _accessCamera = true;

  if (!fullScreenMode) {
    _closeOnCameraSelect();
  }
  final file = await entity.entity.file;

  if (file == null) {
    return null;
  }

  final croppedFile = await ImageCropper.cropImage(
    sourcePath: file.path,
    androidUiSettings: const AndroidUiSettings(
      toolbarTitle: 'Cropper',
      toolbarColor: Color(0xFFF54B64),
      toolbarWidgetColor: Colors.white,
      initAspectRatio: CropAspectRatioPreset.original,
      lockAspectRatio: false,
    ),
    iosUiSettings: const IOSUiSettings(),
  );
  final data = await croppedFile?.readAsBytes();

  if (data == null) {
    return null;
  }

  AssetEntity? assetEntity;
  if (setting.saveCropper) {
    assetEntity = await PhotoManager.editor.saveImage(data);
  } else {
    assetEntity = AssetEntity(
      id: 'temporary',
      typeInt: 1,
      width: 100,
      height: 100,
    );
  }

  if (assetEntity == null) {
    return null;
  }
  _accessCamera = false;
  return LikkEntity(
    entity: assetEntity,
    bytes: data,
  );
}