baumths / flutter_tree_view

A Flutter collection of widgets and slivers that helps bringing your hierarchical data to life.
https://baumths.github.io/flutter_tree_view
MIT License
175 stars 62 forks source link

How to have tree fully expanded at start and on refresh? #61

Closed davoutuk closed 1 year ago

davoutuk commented 1 year ago

I have a Flutter app where I am using the 'flutter_tree_view' widget.

A couple of questions:

  1. What is the best way of making sure the tree is fully expanded on initial display? I was expecting there to be an 'fully expanded at start' property that coul; be set at the tree level.
  2. In my app I can add new nodes to the tree, but I can't find a way of refreshing the tree so that it is also fully expanded after it is refreshed. Any suggestions?
baumths commented 1 year ago

Hey @davoutuk , thank you for using the package!

I'm planning on adding this feature in the future.

In the meantime, you can achieve this behavior by subclassing TreeController and overriding the setExpansionState() and getExpansionState() methods with the appropriate implementation.

davoutuk commented 1 year ago

Thanks for the prompt reply...

A couple of suggestions on the idea of adding new features for expanding the tree....

a). new 'fullyExpandedAtStart' and 'fullyExpandedOnRefresh' properties at 'TreeView' level. Add two new boolean properties that can be used to define if a tree should be fully expanded when first displayed, and when a refresh is required.

b). add new 'nodeExpanded' callback method at 'TreeView' level.

          `bool Function(TreeEntry<T> entry);`

This method would be called for each tree entry allowing the developer to return a 'true' or 'false' if the node is be displayed is to be displayed as expanded. The method would be called prior to calling 'nodeBuilder'. This would allow the developer to programmatically control which nodes are to start as expanded