addLayer method

void addLayer(
  1. Layer layer, {
  2. int removeLayerIndex = -1,
  3. bool blockSelectLayer = false,
  4. bool blockCaptureScreenshot = false,
})

Add a new layer to the image editor.

This method adds a new layer to the image editor and updates the editing state.

Implementation

void addLayer(
  Layer layer, {
  int removeLayerIndex = -1,
  bool blockSelectLayer = false,
  bool blockCaptureScreenshot = false,
}) {
  _addHistory(
      newLayer: layer, blockCaptureScreenshot: blockCaptureScreenshot);

  if (removeLayerIndex >= 0) {
    activeLayers.removeAt(removeLayerIndex);
  }
  if (!blockSelectLayer &&
      _layerInteractionManager.layersAreSelectable(configs) &&
      layerInteraction.initialSelected) {
    /// Skip one frame to ensure captured image in seperate thread will not capture the border.
    WidgetsBinding.instance.addPostFrameCallback((_) async {
      _layerInteractionManager.selectedLayerId = layer.id;
      _controllers.uiLayerCtrl.add(null);
    });
  }
  mainEditorCallbacks?.handleAddLayer(layer);
  setState(() {});
}