TreeViewController class Null safety

Defines the controller needed to display the TreeView.

Used by TreeView to display the nodes and selected node.

This class also defines methods used to manipulate data in the TreeView. The methods (addNode, updateNode, and deleteNode) are non-mutilating, meaning they will not modify the tree but instead they will return a mutilated copy of the data. You can then use your own logic to appropriately update the TreeView. e.g.

TreeViewController controller = TreeViewController(children: nodes);
Node node = controller.getNode('unique_key')!;
Node updatedNode = node.copyWith(
  key: 'another_unique_key',
  label: 'Another Node',
);
List<Node> newChildren = controller.updateNode(node.key, updatedNode);
controller = TreeViewController(children: newChildren);

Constructors

TreeViewController({List<Node> children = const [], String? selectedKey})

Properties

asMap List<Map<String, dynamic>>
Map representation of this object
read-only
children List<Node>
The data for the TreeView.
final
hashCode int
The hash code for this object.
read-onlyinherited
runtimeType Type
A representation of the runtime type of the object.
read-onlyinherited
selectedKey String?
The key of the select node in the TreeView.
final
selectedNode Node?
Get the current selected node. Returns null if there is no selectedKey
read-only

Methods

addNode<T>(String key, Node<T> newNode, {Node? parent, int? index, InsertMode mode = InsertMode.append}) List<Node>
Adds a new node to an existing node identified by specified key. It optionally accepts an InsertMode and index. If no InsertMode is specified, it appends the new node as a child at the end. This method returns a new list with the added node.
collapseAll({Node? parent}) List<Node>
Collapses all node that are children of the parent node parameter. If no parent is passed, uses the root node as the parent.
collapseToNode(String key) List<Node>
Collapses a node and all of the node's ancestors without the need to manually collapse each node.
copyWith<T>({List<Node<T>>? children, String? selectedKey}) TreeViewController
Creates a copy of this controller but with the given fields replaced with the new values.
deleteNode<T>(String key, {Node? parent}) List<Node>
Deletes an existing node identified by specified key. This method returns a new list with the specified node removed.
expandAll({Node? parent}) List<Node>
Expands all node that are children of the parent node parameter. If no parent is passed, uses the root node as the parent.
expandToNode(String key) List<Node>
Expands a node and all of the node's ancestors so that the node is visible without the need to manually expand each node.
getNode<T>(String key, {Node? parent}) Node<T>?
Gets the node that has a key value equal to the specified key.
getParent<T>(String key, {Node? parent}) Node<T>?
Gets the parent of the node identified by specified key.
loadJSON<T>({String json = '[]'}) TreeViewController
Loads this controller with data from a JSON String This method expects the user to properly update the state
loadMap<T>({List<Map<String, dynamic>> list = const []}) TreeViewController
Loads this controller with data from a Map. This method expects the user to properly update the state
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed.
inherited
toggleNode<T>(String key, {Node? parent}) List<Node>
Toggles an existing node identified by specified key. This method returns a new list with the specified node toggled.
toString() String
A string representation of this object.
override
updateNode<T>(String key, Node<T> newNode, {Node? parent}) List<Node>
Updates an existing node identified by specified key. This method returns a new list with the updated node.
withAddNode<T>(String key, Node<T> newNode, {Node? parent, int? index, InsertMode mode = InsertMode.append}) TreeViewController
Adds a new node to an existing node identified by specified key. It returns a new controller with the new node added. This method expects the user to properly place this call so that the state is updated.
withCollapseAll({Node? parent}) TreeViewController
Collapses all nodes down to parent Node. It returns a new controller with the nodes collapsed. This method expects the user to properly place this call so that the state is updated.
withCollapseToNode(String key) TreeViewController
Collapses all nodes down to Node identified by specified key. It returns a new controller with the nodes collapsed. This method expects the user to properly place this call so that the state is updated.
withDeleteNode<T>(String key, {Node? parent}) TreeViewController
Removes an existing node identified by specified key. It returns a new controller with the node removed. This method expects the user to properly place this call so that the state is updated.
withExpandAll({Node? parent}) TreeViewController
Expands all nodes down to parent Node. It returns a new controller with the nodes expanded. This method expects the user to properly place this call so that the state is updated.
withExpandToNode(String key) TreeViewController
Expands all nodes down to Node identified by specified key. It returns a new controller with the nodes expanded. This method expects the user to properly place this call so that the state is updated.
withToggleNode<T>(String key, {Node? parent}) TreeViewController
Toggles the expanded property of an existing node identified by specified key. It returns a new controller with the node toggled. This method expects the user to properly place this call so that the state is updated.
withUpdateNode<T>(String key, Node<T> newNode, {Node? parent}) TreeViewController
Replaces an existing node identified by specified key with a new node. It returns a new controller with the updated node replaced. This method expects the user to properly place this call so that the state is updated.

Operators

operator ==(Object other) bool
The equality operator.
inherited