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
119 stars 69 forks source link

[Bug]: Finalisation pop up acting onImageEditingComplete instead of onCloseEditor #187

Closed HeropolisDa2ny closed 2 months ago

HeropolisDa2ny commented 2 months ago

Package Version

5.0.2

Flutter Version

3.24.0

Platforms

Android, iOS, Web

How to reproduce?

Edit an image with Image Editor - await for a dialog response on onImageEditingComplete that will make you either stay on the editor or leave.

The error starts acting since the new versions > 4.3.3

Screenshot (9 août 2024 20_37_14)

Logs (optional)

No response

Example code (optional)

Future<void> _onImageEditionCompleted(
    BuildContext context, {
    required Uint8List bytes,
  }) async {
    final result = await MyDialog();

    if (result == true) {
      _newImage = bytes;
    } else {
      _newImage = Uint8List(0);
    }
  }

  void _onCloseEditor(BuildContext context) {
    if (_newImage == null || _newImage!.isNotEmpty) {
      Navigator.pop(context, _newImage);
    } else {
      _newImage = null;
    }
  }

ProImageEditor.memory(
      image,
      callbacks: ProImageEditorCallbacks(
        onImageEditingComplete: (bytes) => _onImageEditionCompleted(
          context,
          bytes: bytes,
        ),
        onCloseEditor: () => _onCloseEditor(context),
      ),
      configs: configs,
    );

Device Model (optional)

No response

hm21 commented 2 months ago

I'm not sure if I understand you correctly, but I think that you want that the user confirm before closing the editor. If this is the case, the confirmation should be implemented inside the onCloseEditor function, not in onImageEditingComplete. The onImageEditingComplete function is responsible for displaying the loading-dialog, which allows users to see the same loading-dialog when uploading an image to the server. Below is an example of the correct implementation:

Uint8List? _newImage;

Future<void> _onImageEditionCompleted(
  Uint8List bytes,
) async {
  _newImage = bytes;
}

void _onCloseEditor() {
  final shouldClose = await MyDialog();

  if (shouldClose) {
    Navigator.pop(context, _newImage);
  }
}
HeropolisDa2ny commented 2 months ago

The problem with your method onCloseEditor is that you cannot differentiate if either I'm exiting my editor from my onImageEditionCompleted or my cancelButton, except if I'am doing a variable instantiation on onImageEditionCompleted but it's fine I've just removed my dialog, it is more fluid now.