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

[Feature request] OnEditComplete/Done should have a #62

Closed rahatcse5bu closed 3 months ago

rahatcse5bu commented 3 months ago

Platforms

Android, iOS, Web, Windows, macOS, Linux

Description

Now OnEditImageCompleted works only if I interact with the image(add/edit anything). But I want OnEditImageCompleted callback or similar mechanism when the user doesn't need any editing and click on "done" icon , and it should have a callback/void function that catches the Uint8List bytes, I want to get the Uint8List bytes image data when no user edit is performed and the user click on the 'done' icon image

Why

No response

hm21 commented 3 months ago

If you want to get the bytes even if the user didn't change anything, you can set the config allowCompleteWithEmptyEditing to true which will always return the bytes when the user presses done.

 return ProImageEditor.network(
      'https://picsum.photos/id/237/2000',
      allowCompleteWithEmptyEditing: true,
      ...
    );

If you need more callbacks, you can use the dev version pro_image_editor: ^3.0.0-dev.26, which has many more callbacks and configuration options.

rahatcse5bu commented 3 months ago

in "^3.0.0-dev.26" version, i can't find allowCompleteWithEmptyEditing: true

hm21 commented 3 months ago

In the dev version, this option is now true by default. If you still want to change it, you can do so as follows:

return ProImageEditor.network(
  'https://picsum.photos/id/110/2000',
  callbacks: ProImageEditorCallbacks(
    /// Some callbacks like onImageEditingComplete
  ),
  configs: ProImageEditorConfigs(
    imageGenerationConfigs: ImageGeneratioConfigs(
      allowEmptyEditCompletion: true,
    ),
  ),
);

You can also check out the examples here which show you full code examples.

rahatcse5bu commented 3 months ago

last question please: for the version, pro_image_editor : ^2.4.3, is there any options I want?

hm21 commented 3 months ago

Unfortunately, no, this old version does not support a way that you want. If you really need this old version, you have to do this part by yourself. Below is an example of how to do it:

Uint8List? resultBytes;
String assetPath = ExampleConstants.of(context)!.demoAssetPath;
Navigator.push(
  context,
  MaterialPageRoute(
    builder: (context) => ProImageEditor.asset(
      assetPath,
      onImageEditingComplete: (bytes) async {
        resultBytes = bytes;
        Navigator.pop(context);
      },
    ),
  ),
).whenComplete(() async {
  if (resultBytes == null) {
    // Load the asset as a ByteData
    final ByteData data = await rootBundle.load(assetPath);
    // Convert the ByteData to a Uint8List
    resultBytes = data.buffer.asUint8List();
  }
});

And here is a sample code where you can see how to convert all input formats like File to Uint8List.