addHistory method

void addHistory({
  1. List<Layer>? layers,
  2. Layer? newLayer,
  3. TransformConfigs? transformConfigs,
  4. FilterMatrix? filters,
  5. double? blur,
  6. bool heroScreenshotRequired = false,
  7. bool blockCaptureScreenshot = false,
})

Adds a new state to the history with the given configuration and updates the state manager.

This method is responsible for capturing the current state of the editor, including layers, transformations, filters, and blur settings. It then adds this state to the history, enabling undo and redo functionality. Additionally, it can take a screenshot if required.

  • layers: An optional list of layers to be included in the new state.
  • newLayer: An optional new layer to be added to the current layers.
  • transformConfigs: Optional transformation configurations for the new state.
  • filters: An optional list of filter states to be included in the new state.
  • blur: An optional blur state to be included in the new state.
  • heroScreenshotRequired: A flag indicating whether a hero screenshot is required.

Example usage:

addHistory(
  layers: currentLayers,
  newLayer: additionalLayer,
  transformConfigs: currentTransformConfigs,
  filters: currentFilters,
  blur: currentBlurState,
  heroScreenshotRequired: false,
);

Implementation

void addHistory({
  List<Layer>? layers,
  Layer? newLayer,
  TransformConfigs? transformConfigs,
  FilterMatrix? filters,
  double? blur,
  bool heroScreenshotRequired = false,
  bool blockCaptureScreenshot = false,
}) {
  stateManager.cleanForwardChanges();

  List<Layer> activeLayerList = _layerCopyManager.copyLayerList(activeLayers);

  stateHistory.add(
    EditorStateHistory(
      transformConfigs: transformConfigs ?? stateManager.transformConfigs,
      blur: blur ?? stateManager.activeBlur,
      layers: layers ??
          (newLayer != null
              ? [...activeLayerList, newLayer]
              : activeLayerList),
      filters: filters ?? stateManager.activeFilters,
    ),
  );
  if (!blockCaptureScreenshot) {
    if (!heroScreenshotRequired) {
      _takeScreenshot();
    } else {
      stateManager.heroScreenshotRequired = true;
    }
  } else {
    _controllers.screenshot
        .addEmptyScreenshot(screenshots: stateManager.screenshots);
  }
  stateManager.position++;

  stateManager.setHistoryLimit(configs.stateHistoryConfigs.stateHistoryLimit);
}