Naito
Naito

Reputation: 123

error: Instance member 'cropImage' can't be accessed using static access

class ImagesCropper {
static Future<File?> cropImage(XFile file) async {
final File? croppedImage = await ImageCropper.cropImage(
  sourcePath: file.path,
  aspectRatioPresets:
      Platform.isAndroid ? crossAspectRatioAndroid : crossAspectRatioIos,
  androidUiSettings: androidUiSettings,
  iosUiSettings: iosUiSettings,
);
return croppedImage;
}
}

i put the full code here:

https://controlc.com/9590e7b1

and here's the error in debug console debug console

debug console

Upvotes: 12

Views: 6669

Answers (2)

Lightning Gaming
Lightning Gaming

Reputation: 680

It looks like you are using the ImageCropper package. https://github.com/hnvn/flutter_image_cropper/blob/master/lib/src/cropper.dart#L61 There was an error because the method isn't static so you have to create a new instance of the class to access it

await ImageCropper().cropImage...

The full code correction is below

class ImagesCropper {
static Future<File?> cropImage(XFile file) async {
final File? croppedImage = await ImageCropper().cropImage(
  sourcePath: file.path,
  aspectRatioPresets:
      Platform.isAndroid ? crossAspectRatioAndroid : crossAspectRatioIos,
  androidUiSettings: androidUiSettings,
  iosUiSettings: iosUiSettings,
);
return croppedImage;
}
}

Upvotes: 20

Maikol Bonilla Gil
Maikol Bonilla Gil

Reputation: 719

Just change ImageCropper.cropImage to ImageCropper().cropImage. This will use a new instance of ImageCropper.

Upvotes: 28

Related Questions