TreeView<T> class

A customizable tree view widget for Flutter applications.

TreeView displays hierarchical data in a tree structure, allowing for selection, expansion, and collapse of nodes. It supports various features such as multi-selection, filtering, sorting, and customization of appearance.

The widget is generic over type T, which represents the type of value associated with each node in the tree.

Key features:

  • Hierarchical data display
  • Node selection (single or multi)
  • Expandable/collapsible nodes
  • Optional "Select All" functionality
  • Customizable node appearance
  • Filtering and sorting capabilities
  • Expand/collapse all functionality

Example usage:

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

Constructors

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

Properties

customDrawNode → dynamic Function(TreeNode<T> node, bool isSelected)?
Custom function to draw nodes
final
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
selectAllTrailing Widget Function(BuildContext context)?
The trailing widget displayed for select all node.
final
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