removeLayer method

void removeLayer(
  1. int layerPos, {
  2. Layer? layer,
})

Remove a layer from the editor.

This method removes a layer from the editor and updates the editing state.

Implementation

void removeLayer(int layerPos, {Layer? layer}) {
  int oldIndex = activeLayers
      .indexWhere((element) => element.id == (layer?.id ?? _tempLayer!.id));
  if (oldIndex >= 0) {
    stateHistory[_stateManager.position].layers[oldIndex] =
        _layerCopyManager.copyLayer(_tempLayer ?? layer!);

    mainEditorCallbacks?.handleRemoveLayer(
        stateHistory[_stateManager.position].layers[oldIndex]);
  }

  var layers = _layerCopyManager.copyLayerList(activeLayers);
  layers.removeAt(layerPos);
  _addHistory(layers: layers);
  setState(() {});
}