insertBefore function

bool insertBefore(
  1. FNode parent,
  2. FNode sibling,
  3. FNode newNode
)

Inserts newNode as a child of parent before sibling.

Implementation

bool insertBefore(FNode parent, FNode sibling, FNode newNode) {
  final children = _mutableChildrenOf(parent);
  if (children == null) return false;
  final idx = children.indexWhere((c) => c.id == sibling.id);
  if (idx < 0) return false;
  children.insert(idx, newNode);
  return true;
}