recoverImage method

  1. @override
Future<CroppedFile?> recoverImage()
override

Retrieve cropped image lost due to activity termination (Android only). This method works similarly to retrieveLostData method from image_picker library. Unlike retrieveLostData, does not throw an error on other platforms, but returns null result.

recoverImage as (well as retrieveLostData) will return value on any call after a successful cropImage, so you can potentially get unexpected result when using ImageCropper in different layout. Recommended usage comes down to this:

void crop() async {
  final cropper = ImageCropper();
  final croppedFile = await cropper.cropImage(/* your parameters */);
  // At this point we know that the main activity did survive and we can
  // discard the cached value
  await cropper.recoverImage();
  // process croppedFile value
}

@override
void initState() {
  _getLostData();
  super.initState();
}

void _getLostData() async {
  final recoveredCroppedImage = await ImageCropper().recoverImage();
  if (recoveredCroppedImage != null) {
     // process recoveredCroppedImage value
  }
}

return:

A result file of the cropped image.

See also:

Implementation

@override
Future<CroppedFile?> recoverImage() async {
  if (!Platform.isAndroid) {
    return null;
  }
  final String? resultPath = await methodChannel.invokeMethod('recoverImage');
  return resultPath == null ? null : CroppedFile(resultPath);
}