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

Order issue when add a new node #33

Open
AlehSabadashGmail opened this issue Nov 13, 2023 · 4 comments
Open

Order issue when add a new node #33

AlehSabadashGmail opened this issue Nov 13, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@AlehSabadashGmail
Copy link

Package version - 2.1.0
Type of tree - TreeView.simpleTyped
Flutter version - 3.13.6

There is an order issue when I add a node to a parent node where there are already expanded nodes, a new nodes is added to the wrong place

Screen.Recording.2023-11-13.at.10.37.03.mov
@mjauernig
Copy link

I have a similiar behaivor.

Starting data

  • Folder 1
    • Folder A
      • Child 1

When i update the tree (add Folder B to Folder 1) and Folder A is expanded the visible result is:

  • Folder 1
    • Folder A
    • Folder B
      • Child 1

When i update the tree (add Folder B to Folder 1) and Folder A is collapsed the result is ok:

  • Folder 1
    • Folder A
      • Child 1 (child is on correct position, if i expand Folder A)
    • Folder B

If the starting data has already an existing second folder and i add a third folder the result is also ok.

  • Folder 1
    • Folder A
      • Child 1
    • Folder B

@HoKim98
Copy link

HoKim98 commented Dec 26, 2023

Using overridden root() factory for the root node may resolve this issue.

class MyTreeNode extends TreeNode<MyTreeData> {
  factory MyTreeNode.root({MyTreeData? data}) => MyTreeNode._your_own_factory(
        key: INode.ROOT_KEY,
        data: data,
        // TODO(user): stuffs
      )
        ..isLastChild = true
        ..cacheChildIndices();
}

@shidenggui
Copy link

Also has the same problem

@olerhan
Copy link

olerhan commented Jul 2, 2024

...
  Widget buildInsertBelowButton(IndexedTreeNode item) {
    return Padding(
      padding: const EdgeInsets.only(right: 16.0),
      child: TextButton(
        style: TextButton.styleFrom(
          foregroundColor: Colors.green[800],
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.all(Radius.circular(4)),
          ),
        ),
        child: Text("Insert Below", style: TextStyle(color: Colors.green)),
        onPressed: () {
          _controller?.collapseNode(item); // My solution.
          item.parent?.insertAfter(item, IndexedTreeNode());
        },
      ),
    );
  }
  ...

In my case, my solution is to just add collapseNode for the current node in the insertBelowButton widget's onPressed method.
This issue needs to be fixed at the API level. @jawwad-hassan89 @wasimshigri Thank you.

@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 18, 2024
… the wrong index when the parent is expanded and has children
jawwad-hassan89 added a commit to jawwad-hassan89/animated_tree_view that referenced this issue Aug 18, 2024
…at the wrong index when the parent is expanded and has children
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

6 participants