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
96 stars 59 forks source link

[Bug]: Navigator.pop() does not seem to return data to the caller #72

Closed adamkoch closed 3 months ago

adamkoch commented 3 months ago

Package Version

3.0.4

Flutter Version

3.22.2

Platforms

Android, iOS

How to reproduce?

Not sure if I'm doing something wrong, but I can't seem to get Navigator.pop() to return the value back to the screen that called Navigator.push().

Here is a simple example that doesn't work for me, returning a string instead of the bytes. The final log always has result=null.

Any ideas?

    final result = await Navigator.push(
      context,
      MaterialPageRoute(
        builder: (_) => ProImageEditor.network(
          url,
          callbacks:
              ProImageEditorCallbacks(onImageEditingComplete: (bytes) async {
            // Navigator.of(context).pop(bytes);
            Navigator.of(context).pop('testing');
          }),
        ),
        fullscreenDialog: true,
      ),
    );
    log('result = $result / ${result != null}');

Logs (optional)

No response

Example code (optional)

No response

Device Model (optional)

No response

hm21 commented 3 months ago

Yes, it's not possible because the editor also has to call Navigator.pop(context) internally to close the “loading-dialog”, so you never get any data back, which is why there are so many callbacks. However, if you want to handle the bytes outside the callback, you can do it like this:

Uint8List? result;
await Navigator.push(
  context,
  MaterialPageRoute(
    builder: (_) => ProImageEditor.network(
      url,
      callbacks:
          ProImageEditorCallbacks(onImageEditingComplete: (bytes) async {
        result = bytes;
      }),
    ),
    fullscreenDialog: true,
  ),
);
log('result = ${result?.length}');
adamkoch commented 3 months ago

Ahh thanks! I thought I was doing something wrong in my code. Will give your workaround a go, thanks 👍