Skip to content

app crashes when cropping is done while debugging. #578

@imsumit0303

Description

@imsumit0303

My cropImage function is as below.

Future<void> _cropImage() async {
      final croppedFile = await ImageCropper().cropImage(
        //sourcePath: _pickedFile!.path,
        sourcePath: widget.imageFile.path,
        compressFormat: ImageCompressFormat.jpg,
        compressQuality: 100,
        uiSettings: [
          AndroidUiSettings(
            toolbarTitle: 'Cropper',
            toolbarColor: Colors.deepOrange,
            toolbarWidgetColor: Colors.white,
            initAspectRatio: CropAspectRatioPreset.square,
            lockAspectRatio: false,
            aspectRatioPresets: [
              CropAspectRatioPreset.original,
              CropAspectRatioPreset.square,
              CropAspectRatioPreset.ratio4x3,
            ],
          ),
        ],
      );

      if (croppedFile != null) {
        File croppedFile_file = File(croppedFile.path);
        File? file_webp = await _convertAndSaveWebP(croppedFile_file);
        widget.onImageCropped(file_webp);
        Navigator.pop(context, file_webp);

      } else {
        widget.onImageCropped(
            null); // Handle if cropping was cancelled or failed
        Navigator.pop(context, null);
      }
  }

I called inside initState() as below:

@override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addPostFrameCallback((_) {
      _cropImage();
    });
  }

If I put a breakpoint at the line "if (croppedFile != null) {" that means when cropping is done and debugger is on. Just after 4-5 seconds app crashes.

Note: it gives me croppedFile but it crashes as well.

Why it is happening? Can anyone guide me resolve this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions