move method

void move(
  1. String id, {
  2. required String parent,
  3. int? index,
})

Reparents the node. This is a drag between containers.

Implementation

void move(String id, {required String parent, int? index}) {
  final moving = find(id);
  final target = find(parent);
  if (moving == null || target == null) {
    throw ArgumentError('No such node.');
  }
  // Dropping a container into its own subtree would orphan the tree.
  if (_findIn(moving, parent) != null) {
    throw ArgumentError(
      'Cannot move a node into its own subtree.',
    );
  }
  remove(id);
  insert(moving, parent: parent, index: index);
}