TreeNode class

This class represents one node in the Tree.

  • Adding children:

    Use either addChild or addChildren to modify the children of this node. The children property is not present in the constructor to make it easy to set the parent of this node automatically.

  • Removing children:

    Use either removeChild or clearChildren to remove any child from this node, both methods set children's parent property to null.

Inheritance

Constructors

TreeNode({required String id, String label = '', Object? data})
Creates a TreeNode.

Properties

ancestors Iterable<TreeNode>
Returns the path from the root node to this node, not including this.
no setter
children UnmodifiableSetView<TreeNode>
The list of child nodes.
no setter
data Object?
Any data you may want to store or pass around.
final
depth int
The distance between this node and the root node.
no setter
descendants Iterable<TreeNode>
Returns an Iterable of every TreeNode under this.
no setter
hasChildren bool
Whether this node has children or not.
no setter
hashCode int
The hash code for this object.
no setteroverride
hasNextSibling bool
Whether or not this node is the last child of its parent.
no setter
id String
An id to easily find this node in the Tree.
final
isLeaf bool
Whether this node is the last one in the subtree (empty children).
no setter
isMostTopLevel bool
Whether this node is a direct child of the root node.
no setter
isRoot bool
Whether or not this node is the root.
no setter
label String
The label (name, title, ...) of this node.
final
lastChild TreeNode?
Returns the last child of this node or null if children is empty.
no setter
nullableDescendants Iterable<TreeNode?>
Same as descendants but with nullable return, useful when filtering nodes to use orElse: () => null when no node was found.
no setter
parent TreeNode?
If null, this node is the root of the tree or it doesn't belong to any node yet.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

addChild(TreeNode child) → void
Adds a single child to this node and sets its parent property to this.
addChildren(Iterable<TreeNode> nodes) → void
Adds a list of children to this node.
clearChildren() List<TreeNode>
Removes all children from this node and sets their parent to null.
compareTo(TreeNode other) int
Compares this object to another object.
override
delete({bool recursive = false}) → void
Removes this node from the tree.
find(String id) TreeNode?
Starting from this node, searches the subtree looking for a node id that match id, returns null if no node was found with the given id.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
removeChild(TreeNode child) → void
Removes a single child from this node and set its parent to null.
toString() String
A string representation of this object.
override

Operators

operator ==(covariant TreeNode other) bool
The equality operator.
override
operator [](int index) TreeNode
Convenience operator to get the indexth child.