Order issue when add a new node
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
https://github.com/embraceitmobile/animated_tree_view/assets/90776958/f6d07408-64ba-44d7-90ab-2e5d03a417c2
I have a similiar behaivor.
Starting data
- Folder 1
- Folder A
- Child 1
- Folder A
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
- Folder A
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
- Folder A
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();
}
Also has the same problem
...
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.