How to scroll to a key
Thank you for creating the awesome Tree view. When a tree view controller is initialized with a selected key , it doesn’t scroll to the node of selected key, which is not displayed on the current screen. I need to manually scroll down to see the selected key node.
Any suggestions, will be helpful. I also didn’t see any api calls like scrolltoKey().
I am using an expanded widget in a column without any scroll bars.
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Expanded(
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
),
padding: EdgeInsets.all(10),
child: buildprojectTree(),
),
),
],
),
_treeViewController = TreeViewController(
children:nodes,selectedKey: "P:41;F:13");
Widget buildprojectTree() {
return TreeView(
controller: state._treeViewController,
allowParentSelect: false,
supportParentDoubleTap: false,
primary: true,
onExpansionChanged: (key,expanded) {
Node node = state._treeViewController.getNode(key);
if (node != null)
{
List<Node> updated;
updated = state._treeViewController.updateNode(
key, node.copyWith(expanded: expanded));
state.setState(() {
state._treeViewController = state._treeViewController.copyWith(children: updated);
});
}
},
onNodeTap: (key) {
state.setState(() {
state._treeViewController =
state._treeViewController.copyWith(selectedKey: key);
});
},
theme: _treeViewTheme,
);
}
Comments (3)
-
-
First thank you for the excellent widget.
I would also like this functionality. (scrollTo(node) or Node.scrollTo() method)The solution proposed by Gustav Gussi will probably work but feels alot like a hack.
So if you have time to get this implement this functionality it would be awesome!Thank you,
Stefan
-
Gustav’s solution works except for tree nodes with different heights. I think
Scrollable.ensureVisible
should be called insideTreeView
widget's ListView. Otherwise, accurately estimating the offset of the aimed node is very difficult. We can’t accessTreeNode
widgets insideTreeView
, so callingScrollable.ensureVisible
from outside is impossible either. - Log in to comment
I was going to ask author to allow to add scroll controller parameter for tree but in time I noticed the property primary. So I here it is my positioning idea:
Wrap the TreeView with PrimaryScrollController.