doneEditing method

void doneEditing()

Complete the editing process and return the edited image.

This function is called when the user is done editing the image. If no changes have been made or if the image has no additional layers, it cancels the editing process and closes the editor. Otherwise, it captures the current state of the image, including any applied changes or layers, and returns it as a byte array.

Before returning the edited image, a loading dialog is displayed to indicate that the operation is in progress.

Implementation

void doneEditing() async {
  if (_stateManager.editPosition <= 0 && activeLayers.isEmpty) {
    final allowCompleteWithEmptyEditing =
        widget.allowCompleteWithEmptyEditing;
    if (!allowCompleteWithEmptyEditing) {
      return closeEditor();
    }
  }
  setState(() => _layerInteraction.selectedLayerId = '');

  _doneEditing = true;
  LoadingDialog loading = LoadingDialog()
    ..show(
      context,
      i18n: i18n,
      theme: _theme,
      designMode: designMode,
      message: i18n.doneLoadingMsg,
      imageEditorTheme: imageEditorTheme,
    );

  Uint8List bytes = Uint8List.fromList([]);
  try {
    bytes = await _controllers.screenshot.capture(
          pixelRatio: configs.removeTransparentAreas ? null : _pixelRatio,
        ) ??
        bytes;
  } catch (_) {}

  if (configs.removeTransparentAreas) {
    bytes = removeTransparentImgAreas(bytes) ?? bytes;
  }

  await widget.onImageEditingComplete(bytes);

  if (mounted) loading.hide(context);

  widget.onCloseEditor?.call();
}