TreeView<T> class

A customizable tree view widget that displays hierarchical data.

This widget creates a tree structure from a list of TreeNodes and allows for selection, expansion, and collapsing of nodes. It also supports filtering and sorting of nodes.

The onSelectionChanged callback is called whenever the selection state of any node changes.

Example:

TreeView<String>(
  nodes: [
    TreeNode(
      label: 'Root',
      children: [
        TreeNode(label: 'Child 1'),
        TreeNode(label: 'Child 2'),
      ],
    ),
  ],
  onSelectionChanged: (selectedValues) {
    print('Selected values: $selectedValues');
  },
)

Method Examples:

treeViewKey.currentState?.filter((node) => node.label.contains('Search'));
treeViewKey.currentState?.sort((a, b) => a.label.compareTo(b.label));
treeViewKey.currentState?.selectAll(true);
treeViewKey.currentState?.getSelectedValues();
treeViewKey.currentState?.getSelectedNodes();
Inheritance

Constructors

TreeView.new({Key? key, required List<TreeNode<T>> nodes, required dynamic onSelectionChanged(List<T?>), ThemeData? theme, bool showSelectAll = false, Widget? selectAllWidget, int? initialExpandedLevels, bool showExpandCollapseButton = false})
Creates a TreeView widget.
const

Properties

hashCode int
The hash code for this object.
no setterinherited
initialExpandedLevels int?
The number of levels to initially expand. If null, no nodes are expanded.
final
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
nodes List<TreeNode<T>>
The root nodes of the tree.
final
onSelectionChanged → dynamic Function(List<T?>)
Callback function called when the selection state changes.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
selectAllWidget Widget?
Custom widget to replace the default "Select All" checkbox.
final
showExpandCollapseButton bool
Whether to show the expand/collapse all button.
final
showSelectAll bool
Whether to show a "Select All" checkbox.
final
theme ThemeData?
Optional theme data for the tree view.
final

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() TreeViewState<T>
Creates the mutable state for this widget at a given location in the tree.
override
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
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
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

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