void replaceWith(Layer newLayer)

Replaces this layer with the given layer in the parent layer's child list

Source

void replaceWith(Layer newLayer) {
  assert(_parent != null);
  assert(newLayer._parent == null);
  assert(newLayer._nextSibling == null);
  assert(newLayer._previousSibling == null);
  newLayer._nextSibling = _nextSibling;
  if (_nextSibling != null)
    newLayer._nextSibling._previousSibling = newLayer;
  newLayer._previousSibling = _previousSibling;
  if (_previousSibling != null)
    newLayer._previousSibling._nextSibling = newLayer;
  assert(() {
    Layer node = this;
    while (node.parent != null)
      node = node.parent;
    assert(node != newLayer); // indicates we are about to create a cycle
    return true;
  });
  newLayer._parent = _parent;
  if (_parent._firstChild == this)
    _parent._firstChild = newLayer;
  if (_parent._lastChild == this)
    _parent._lastChild = newLayer;
  _nextSibling = null;
  _previousSibling = null;
  _parent = null;
}