TreeViewController class

A controller for a TreeView.

A TreeViewController provides programmatic control over a TreeView, including managing items, selection, and expansion state.

This is similar to ScrollController or TextEditingController in Flutter.

{@tool snippet} This example shows how to use a TreeViewController:

final controller = TreeViewController(
  items: [
    TreeViewItem(content: Text('Item 1'), value: 'item1'),
    TreeViewItem(content: Text('Item 2'), value: 'item2'),
  ],
);

TreeView(controller: controller);

// Later, programmatically manipulate the tree:
controller.expandAll();
controller.addItem(TreeViewItem(content: Text('New'), value: 'new'));
controller.addItems([...], parent: someItem);
controller.moveItem(someItem, newParent: targetItem);
controller.selectItem(controller.items.first);

{@end-tool}

See also:

Mixed-in types

Constructors

TreeViewController({List<TreeViewItem>? items})
Creates a TreeViewController.

Properties

hashCode int
The hash code for this object.
no setterinherited
hasListeners bool
Whether any listeners are currently registered.
no setterinherited
isAttached bool
Whether this controller is attached to a TreeView.
no setter
items List<TreeViewItem>
The items managed by this controller.
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

addItem(TreeViewItem item, {TreeViewItem? parent, int? index}) → void
Adds item as a child of parent.
addItems(List<TreeViewItem> items, {TreeViewItem? parent}) → void
Adds multiple items as children of parent.
addListener(VoidCallback listener) → void
Register a closure to be called when the object changes.
inherited
collapseAll() → void
Collapses all items in the tree recursively.
collapseItem(TreeViewItem item) → void
Collapses item.
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
override
deselectAll() → void
Deselects all items in the tree recursively.
deselectItem(TreeViewItem item) → void
Deselects item.
dispose() → void
Discards any resources used by the object.
override
expandAll() → void
Expands all items in the tree recursively.
expandItem(TreeViewItem item) → void
Expands item if it has children.
getItemFromValue(dynamic value) TreeViewItem?
Finds a TreeViewItem by its value.
moveItem(TreeViewItem item, {TreeViewItem? newParent, int? index}) bool
Moves item to a new position in the tree.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyListeners() → void
Call all the registered listeners.
inherited
removeItem(TreeViewItem item) bool
Removes item from the tree.
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that are notified when the object changes.
inherited
selectAll() → void
Selects all items in the tree recursively.
selectItem(TreeViewItem item) → void
Selects item.
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringShort() String
A brief description of this object, usually just the runtimeType and the hashCode.
inherited

Operators

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