expandItem method

void expandItem(
  1. TreeNode treeNode
)

Begin expand

Implementation

void expandItem(TreeNode treeNode) {
  List items = [treeNode.item];
  while (items.length > 0) {
    var currentItem = items.first;
    items.remove(currentItem);
    NodeController controller =
        _rootController!.controllerOfItem(currentItem)!;
    List oldChildItems = [];
    for (NodeController controller in controller.childControllers) {
      oldChildItems.add(controller);
    }
    int numberOfChildren = itemChildrenLength(currentItem);
    List<int> indexes = [];
    for (int i = 0; i < numberOfChildren; i++) {
      indexes.add(i);
    }
    var currentChildControllers = createNodeController(controller, indexes);
    List<NodeController> childControllersToInsert = [];
    List<int> indexesForInsertions = [];
    List<NodeController> childControllersToRemove = [];
    List<int> indexesForDeletions = [];
    for (NodeController loopNodeController in currentChildControllers) {
      if (!controller.childControllers.contains(loopNodeController) &&
          !oldChildItems.contains(controller.treeNode.item)) {
        childControllersToInsert.add(loopNodeController);
        int index = currentChildControllers.indexOf(loopNodeController);
        assert(index != -1);
        indexesForInsertions.add(index);
      }
    }

    for (NodeController loopNodeController in controller.childControllers) {
      if (!currentChildControllers.contains(loopNodeController) &&
          !childControllersToInsert.contains(loopNodeController)) {
        childControllersToRemove.add(loopNodeController);
        int index = controller.childControllers.indexOf(loopNodeController);
        assert(index != -1);
        indexesForDeletions.add(index);
      }
    }

    controller.removeChildControllers(indexesForDeletions);
    controller.insertChildControllers(
        childControllersToInsert, indexesForInsertions);
    bool expandChildren = false;
    if (expandChildren) {
      for (NodeController nodeController in controller.childControllers) {
        items.add(nodeController.treeNode.item);
      }
    }
    controller.expandAndExpandChildren(false);
    notifyListeners();
  }
}