Comments (3)
To programmatically expand or collapse a node, use the toggleExpansion method of the TreeViewController
To get the TreeViewController
, wrap the TreeViewState
inside a GlobalKey
like final globalKey = GlobalKey<TreeViewState>()
, and then get the controller from the currentState like this globalKey.currentState?.controller;
Full code sample to use the TreeViewController
:
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}"),
),
),
);
}
}
from animated_tree_view.
hi, you didn't really answer the first question
expand all child nodes
if you could respond to this that'd be great
from animated_tree_view.
@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.
For the time being you can use this handy extension to achieve the same.
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);
}
}
}
from animated_tree_view.
Related Issues (20)
- How to refresh UI state for node after check-box is clicked on such node? HOT 1
- Dynamic change of root HOT 2
- After updating the data, the connected line was disconnected HOT 3
- Why node.data can be null? HOT 1
- Possible bug? HOT 6
- Not generating unique keys for the nodes HOT 4
- Build custom ExpansionIndicator HOT 1
- Order issue when add a new node HOT 4
- Tree is getting collapsed moving from one tab to another/screen HOT 3
- Question: Editing Tree Hierarchy
- 2D Scrolling HOT 1
- How to load the tree data only when it is needed? HOT 4
- How to detect if node is expanding or shrinking in onItemTap method? HOT 1
- expandAllChildren HOT 3
- Get objects in the tree
- Expand on ExpansionIndicator tap instead of on Node tap HOT 3
- node.add() method causes break in linking tree lines: File explorer example HOT 3
- is Infinite nesting expands the fold list? HOT 1
- Please make AnimationController in ExpansionIndicatorState public
- v2.0.1 ,add node to rootNode will produce repeated subNode UI
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from animated_tree_view.