I want to delete the captured image via wechat_camera_picker Flutter

487 Views Asked by At

For image_picker MainActivity destruction I wanted to use other plugin to pick image. And I found wechat_camera_picker as an alternative. But there was a problem while capturing the image. The captured image saved on Local Storage after selecting the image. Here is my code.

Future<File> getImageByCamera(BuildContext context) async {
    try{
      final AssetEntity result = await CameraPicker.pickFromCamera(
        context,
        pickerConfig: CameraPickerConfig(
          shouldDeletePreviewFile: true,
          enableRecording: false,
          textDelegate: EnglishCameraPickerTextDelegate(),
        ),
      );
      if(result != null){
        File pickedFile = await result.file;
        pickedFile = await compressFile(pickedFile);
        return pickedFile;
      }else{
        return null;
      }
    }catch(error){
      print(error);
      return null;
    }
  }

Does anyone have any solution of this problem?

1

There are 1 best solutions below

0
On BEST ANSWER

you can use the below function to delete the locally stored file.

  Future<bool> deleteFile(File pickedFile) async {
    try {
      await pickedFile.delete();
      return true; 
    } catch (e) {
      return false;
    }
  }   

You can check the Delete Function Documation for referenece.