You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
All the recent enhancements to TreeView are very much appreciated, especially the narrowSpacing behavior and the keyboard navigation!
My application is using both single-selection and multi-selection TreeView widgets, and I've noticed some bugs and useful enhancements:
🐛 A single-selection TreeView that is given an initial list of items that has a single item selected may improperly clear out the selection state of this item if the single selected item has any children (initState calls buildItems and that improperly calls updateSelected).
🐛 In single-selection mode, if a child item is selected, and then the parent is collapsed so that the child is hidden, and then the parent item is selected, the child item's selected state is not properly set to false. If you expand the parent, then the child item will still be selected and it will have multiple items selected even though it's a single-selection tree view.
onItemInvoked is called for 3 different reasons: when the item's selection state is toggled, when the item is expanded or collapsed, or when the item is otherwise pressed (or space/enter is pressed). Without knowing the item invoke reason, it's not easy to implement logic that toggles the selection state of an item only when it's pressed (and not for the other two reasons).
Along the same lines, an application may want to toggle the selection state of a given item in a multi-selection mode tree, and some helper methods should be exposed so that the same logic can be used to set the new selection state of an item and all of its children, as well as to appropriately update the selection state of the parent(s) of an item.
You may want to allow a parent item to remain selected even if the user deselects all of the children (it would show the "indeterminate" checkbox state in this case). This can be useful if the parent
For this reason, you may also want to have included in the list of selectedItems passed to the onSelectionChanged callback any parent items that are partially selected.
I'll submit a PR that fixes these bugs and implements these enhancements. With these enhancements, my application can now easily programmatically change the selection state when an item is clicked/pressed (storing selection state in riverpod and propagating changed item list back to treeview widget through provider rebuild), and also parent items can remain selected even if children are all deselected. Note that it still defaults to the old behavior.
The text was updated successfully, but these errors were encountered:
You may want to allow a parent item to remain selected even if the user deselects all of the children (it would show the "indeterminate" checkbox state in this case).
I don't think this behavior exists in the native implementation. Can you tell an use-case for this?
I don't think this behavior exists in the native implementation. Can you tell an use-case for this?
Let's say that the tree view is showing a list of folders defining which folders you want to search for files within. It's possible that the user wants to search for files in a given parent directory but not any of that parent directory's children directories. That would require the ability for the children to be deselected but the parent to remain selected. For example:
Root
|--> Parent
|-->Child1
|-->Child2
|-->Child3
The user might want to search for files in the Root and Parent directories, but not for files in the Child[123] subdirectories`, etc.
Another common use case are backup applications where the user is choosing what they want to restore (and the UX typically shows a folder tree on the left, and a flat listview on the right showing files just within the currently highlighted directory), and they want to restore the files in the parent directory, but they don't want to restore content in the child subdirectories.
It definitely shouldn't be the default behavior, but is a nice optional behavior needed for cases where each treeview item might logically contain things besides just the child items shown in the tree.
All the recent enhancements to
TreeView
are very much appreciated, especially thenarrowSpacing
behavior and the keyboard navigation!My application is using both single-selection and multi-selection
TreeView
widgets, and I've noticed some bugs and useful enhancements:TreeView
that is given an initial list of items that has a single item selected may improperly clear out the selection state of this item if the single selected item has any children (initState
callsbuildItems
and that improperly callsupdateSelected
).onItemInvoked
is called for 3 different reasons: when the item's selection state is toggled, when the item is expanded or collapsed, or when the item is otherwise pressed (or space/enter is pressed). Without knowing the item invoke reason, it's not easy to implement logic that toggles the selection state of an item only when it's pressed (and not for the other two reasons).selectedItems
passed to theonSelectionChanged
callback any parent items that are partially selected.I'll submit a PR that fixes these bugs and implements these enhancements. With these enhancements, my application can now easily programmatically change the selection state when an item is clicked/pressed (storing selection state in riverpod and propagating changed item list back to treeview widget through provider rebuild), and also parent items can remain selected even if children are all deselected. Note that it still defaults to the old behavior.
The text was updated successfully, but these errors were encountered: