openCropRotateEditor method

void openCropRotateEditor()

Opens the crop rotate editor.

This method opens the crop editor, allowing the user to crop and rotate the image.

Implementation

void openCropRotateEditor() async {
  if (!_inited) await _decodeImageCompleter.future;

  openPage<TransformConfigs?>(
    CropRotateEditor.autoSource(
      key: cropRotateEditor,
      file: editorImage.file,
      byteArray: editorImage.byteArray,
      assetPath: editorImage.assetPath,
      networkUrl: editorImage.networkUrl,
      initConfigs: CropRotateEditorInitConfigs(
        configs: configs,
        callbacks: callbacks,
        theme: _theme,
        layers: stateManager.activeLayers,
        transformConfigs:
            stateManager.stateHistory[stateManager.position].transformConfigs,
        mainImageSize: sizesManager.decodedImageSize,
        mainBodySize: sizesManager.bodySize,
        enableFakeHero: true,
        appliedBlurFactor: stateManager.activeBlur,
        appliedFilters: stateManager.activeFilters,
        onDone: (transformConfigs, fitToScreenFactor) async {
          List<Layer> updatedLayers = LayerTransformGenerator(
            layers: stateManager.activeLayers,
            activeTransformConfigs: stateManager.transformConfigs,
            newTransformConfigs: transformConfigs,
            layerDrawAreaSize: sizesManager.bodySize,
            undoChanges: false,
            fitToScreenFactor: fitToScreenFactor,
          ).updatedLayers;

          decodeImage(transformConfigs);
          addHistory(
            transformConfigs: transformConfigs,
            layers: updatedLayers,
            heroScreenshotRequired: true,
          );

          /// Important to reset the layer hero positions
          if (activeLayers.isNotEmpty) {
            _controllers.layerHeroResetCtrl.add(true);
            await Future.delayed(const Duration(milliseconds: 60));
            _controllers.layerHeroResetCtrl.add(false);
          }

          setState(() {});
        },
      ),
    ),
  ).then((transformConfigs) async {
    if (transformConfigs != null) {
      setState(() {});
      mainEditorCallbacks?.handleUpdateUI();
    }
  });
}