-
Notifications
You must be signed in to change notification settings - Fork 32
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
Expand all nodes default or special node #5
Comments
To programmatically expand or collapse a node, use the toggleExpansion method of the TreeViewController To get the Full code sample to use the class _MyHomePageState extends State<MyHomePage> {
final globalKey = GlobalKey<TreeViewState>();
TreeViewController? get controller => globalKey.currentState?.controller;
final tree = TreeNode<String>();
void toggleExpansion(String nodePath) {
final node = controller?.elementAt(nodePath);
if (node != null) controller?.toggleExpansion(node);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text(widget.title)),
body: TreeView.simple<String>(
key: globalKey,
tree: tree,
builder: (context, level, item) => ListTile(
title: Text("Item ${item.level}-${item.key}"),
),
),
);
}
} |
hi, you didn't really answer the first question
if you could respond to this that'd be great |
@kespaldon right now there is no builtin method to expand all the children of a node. So you will have to recursively iterate through the children, and expand them. I will add a utility method to handle expansion of all children in the next release. extension TreeControllerX<Data, Tree extends ITreeNode<Data>>
on TreeViewController {
/// Utility method for programmatically expanding all the child nodes. By default
/// only the immediate children of the node will be expanded.
/// Set [recursive] to true for expanding all the child nodes until the leaf is
/// reached.
void expandAllChildren(Tree node, {bool recursive = false}) {
for (final child in node.childrenAsList) {
toggleExpansion(child as Tree);
if (child.childrenAsList.isNotEmpty) expandAllChildren(child);
}
}
} |
Hi, Is there any way to expand all child nodes or specified node after all view build is complete? I changed the 'isExpanded' property of the TreeNode to true but it had no effect.
The text was updated successfully, but these errors were encountered: