Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node.add() method causes break in linking tree lines: File explorer example #43

Open
Uche01 opened this issue Mar 13, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@Uche01
Copy link

Uche01 commented Mar 13, 2024

I am adding nodes directly to a parent using method: node.add(). Items are added but the lines showing node link appears to break for the newly added node. See code and image below:
node.add(SeasonNode());
node-break-screenshot

@Uche01 Uche01 changed the title Unpleasant default item add animation for treeview with simpleTyped node.add() method causes break in linking tree lines: File explorer example Mar 15, 2024
@pdsliuzhen
Copy link

I have also encountered this problem, may I ask if the problem has been solved

@Michal-MK
Copy link

Michal-MK commented May 26, 2024

I solved it by cloing the repo and adding

  void fixLastChild() {
    for (var i = 0; i < childrenAsList.length; i++) {
      if (childrenAsList[i] is TreeNode) {
        (childrenAsList[i] as TreeNode).isLastChild = i == childrenAsList.length - 1;
      }
    }
  }

to listenable_node.dart and altering all the add addAll remove etc.. to call it after the super calls.

Then in _IndentationPainter I added an extra parameter isLastChild and initialize it from the node in constructor. Taking it from the node itself did not work for me.

return CustomPaint(
      foregroundPainter: _IndentationPainter(
        indentation: indentation,
        node: node,
        isLastChild: node.isLastChild,
        minLevelToIndent: minLevelToIndent,
      ),
      child: content,
    );

And alter it's shouldRepaint

  @override
 bool shouldRepaint(_IndentationPainter oldDelegate) {
   return indentation != oldDelegate.indentation || node != oldDelegate.node || isLastChild != oldDelegate.isLastChild;
 }

Do not that it is O(n) for every operation so for large trees may be inadequate. It works for my specific usecase.

@olerhan
Copy link

olerhan commented Jul 4, 2024

I'm not sure if this error originated from me, but seeing this error here made me start thinking that it was caused by the package. My solution was different. I created the following special methods. It's easier than the method above and I think it will work for everyone facing this problem. It worked for me.

  Future<void> insertNodeBelow(IndexedTreeNode<dynamic> referenceNode,
      IndexedTreeNode<dynamic> newNode) async {
    if (referenceNode.isLastChild) {
      referenceNode.isLastChild = false;
      newNode.isLastChild = true;
    }
    referenceNode.parent?.insertAfter(referenceNode, newNode);
//my code
  }

and...

  Future<void> addNode(
      IndexedTreeNode<dynamic> parent, IndexedTreeNode<dynamic> newNode) async {
    for (final child in parent.children) {
      if (child is IndexedTreeNode<dynamic>) {
        child.isLastChild = false;
      }
    }
    newNode.isLastChild = true;
    parent.add(newNode);
//my code
  }

This is it.

I hope the package owner does something to fix these bugs.

@jawwad-hassan89 jawwad-hassan89 added the bug Something isn't working label Aug 16, 2024
jawwad-hassan89 added a commit to jawwad-hassan89/animated_tree_view that referenced this issue Aug 25, 2024
… to update the indents on tree item update
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants