moveLayerListPosition method

void moveLayerListPosition({
  1. required int oldIndex,
  2. required int newIndex,
})

Moves a layer in the list to a new position.

  • oldIndex is the current index of the layer.
  • newIndex is the desired index to move the layer to.

Implementation

void moveLayerListPosition({
  required int oldIndex,
  required int newIndex,
}) {
  List<Layer> layers = _layerCopyManager.copyLayerList(activeLayers);
  if (newIndex > oldIndex) {
    var item = layers.removeAt(oldIndex);
    layers.insert(newIndex - 1, item);
  } else {
    var item = layers.removeAt(oldIndex);
    layers.insert(newIndex, item);
  }
  _addHistory(layers: layers);
  setState(() {});
}