doneEditing method

  1. @protected
void doneEditing({
  1. dynamic returnValue,
  2. required EditorImage editorImage,
  3. Function? onCloseWithValue,
  4. dynamic onSetFakeHero(
    1. Uint8List?
    )?,
})

This function is for internal use only and is marked as protected. Please use the done() method instead.

Implementation

@protected
void doneEditing({
  dynamic returnValue,
  required EditorImage editorImage,
  Function? onCloseWithValue,
  Function(Uint8List?)? onSetFakeHero,
}) async {
  if (createScreenshot) return;
  initConfigs.onImageEditingStarted?.call();

  if (initConfigs.convertToUint8List) {
    createScreenshot = true;
    LoadingDialog.instance.show(
      context,
      configs: configs,
      theme: theme,
      message: i18n.doneLoadingMsg,
    );

    /// Ensure the image infos are read
    if (imageInfos == null) await setImageInfos();
    if (!mounted) {
      LoadingDialog.instance.hide();
      return;
    }

    /// Capture the final screenshot
    bool screenshotIsCaptured = screenshotHistoryPosition > 0 &&
        screenshotHistoryPosition <= screenshotHistory.length;
    Uint8List? bytes = await screenshotCtrl.captureFinalScreenshot(
      imageInfos: imageInfos!,
      backgroundScreenshot: screenshotIsCaptured
          ? screenshotHistory[screenshotHistoryPosition - 1]
          : null,
      originalImageBytes: screenshotHistoryPosition > 0
          ? null
          : await editorImage.safeByteArray(context),
    );

    createScreenshot = false;

    /// Return final image that the user can handle it but still with the
    /// active loading dialog
    await initConfigs.onImageEditingComplete
        ?.call(bytes ?? Uint8List.fromList([]));

    /// Precache the image for the case the user require the hero animation
    if (onSetFakeHero != null) {
      if (bytes != null && mounted) {
        await precacheImage(MemoryImage(bytes), context);
      }
      onSetFakeHero.call(bytes);
    }

    /// Hide the loading dialog
    LoadingDialog.instance.hide();

    initConfigs.onCloseEditor?.call();
  } else {
    if (onCloseWithValue == null) {
      Navigator.pop(context, returnValue);
    } else {
      onCloseWithValue.call();
    }
  }
}