removeItem method

void removeItem(
  1. dynamic id,
  2. ActionOnNodeRemoval action
)

to remove an item from the list

Implementation

void removeItem(id, ActionOnNodeRemoval action) {
  assert(toSetter != null,
      "toSetter is not provided, you can't use this function without providing an toSetter");
  List subnodes =
      _nodes.where((element) => toProvider(element.data) == id).toList();
  switch (action) {
    case ActionOnNodeRemoval.unlink:
      for (Node<E> node in subnodes) {
        toSetter!(node.data, null);
      }
      break;
    case ActionOnNodeRemoval.connectToParent:
      for (Node<E> node in subnodes) {
        toSetter!(node.data, toProvider(node.data));
      }
      break;
  }
  _nodes.removeWhere((element) => idProvider(element.data) == id);
  calculatePosition();
}