hm21 / pro_image_editor

The pro_image_editor is a Flutter widget designed for image editing within your application. It provides a flexible and convenient way to integrate image editing capabilities into your Flutter project.
https://hm21.github.io/pro_image_editor/
BSD 3-Clause "New" or "Revised" License
94 stars 59 forks source link

[Bug]: After the edit is completed, if another edit is performed, the returned bytes are maintained from the previous edit, which is a problem. #160

Closed ghdrb9138 closed 1 month ago

ghdrb9138 commented 1 month ago

Package Version

4.2.7

Flutter Version

3.19.5

Platforms

Android, iOS

How to reproduce?

When receiving a photo file through the image picker, and then getting the bytes through the pro_image_editor file, and then repeating the same process of receiving a photo through the image picker and getting the bytes through the pro_image_editor file, there is a phenomenon where the previous bytes remain as residue.

The sequence is:

1) _pickedFile => Uint8List of the first photo received from the gallery 2) bytes => the value coming from onImageEditingComplete 3) _pickedFile changed => the bytes value received as a global variable 4) _pickedFile => Uint8List of a different photo 5) bytes => the value coming from onImageEditingComplete (same as the bytes from step 2) 6) _pickedFile changed => the bytes value received as a global variable (same as the bytes from step 2)

image

image

Logs (optional)

No response

Example code (optional)

Future getImage(BuildContext context, ImageSource source) async {
    final _pickedFile = await picker.pickImage(source: source);
    tempPickedImage = await _pickedFile!.readAsBytes();
    bool _tempBool = false;

    if (_pickedFile != null) {
      if (context.mounted) {
        /** PRO */
        if (context.mounted) {
          await Navigator.push(
            context,
            MaterialPageRoute(
              builder: (context) => ProImageEditor.memory(
                tempPickedImage,
                callbacks: ProImageEditorCallbacks(
                  onCloseEditor: () async {
                    widget.controller.imagePickState.value = false;
                    Navigator.pop(context);
                    print('_pickedFile changed');
                    print(editedImage);
                    setState(() {});
                  },
                  onImageEditingComplete: (Uint8List bytes) async {
                    print('_pickedFile');
                    print(await _pickedFile.readAsBytes());
                    print('bytes');
                    print(bytes);
                    editedImage = bytes;
                    // tempImage = await convertUint8ListToXFile(bytes);
                    _tempBool = true;
                  },
                ),
                configs: ProImageEditorConfigs(
                    heroTag: _pickedFile.path,
                    imageGenerationConfigs: const ImageGeneratioConfigs(
                        allowEmptyEditCompletion: true)),
              ),
            ),
          );
          tempImage = await convertUint8ListToXFile(editedImage);
          if (_tempBool) {
            setState(
              () {
                widget.controller.image = tempImage;
                widget.controller.imagePickState.value = true;
              },
            );
          }
        }
      }
    }
  }

Device Model (optional)

No response