insert method Null safety

void insert(
  1. dynamic point
)

Implementation

void insert(point) {
  Node? innerSearch(Node? node, Node? parent) {
    if (node == null) {
      return parent;
    }

    var dimension = _dimensions[node.dimension];
    if (point[dimension] < node.obj[dimension]) {
      return innerSearch(node.left, node);
    } else {
      return innerSearch(node.right, node);
    }
  }

  var insertPosition = innerSearch(_root, null), newNode, dimension;

  if (insertPosition == null) {
    _root = Node(point, 0, null);
    return;
  }

  newNode = Node(point, (insertPosition.dimension + 1) % _dimensions.length,
      insertPosition);
  dimension = _dimensions[insertPosition.dimension];

  if (point[dimension] < insertPosition.obj[dimension]) {
    insertPosition.left = newNode;
  } else {
    insertPosition.right = newNode;
  }
}