TreeView<T> constructor

const TreeView<T>({
  1. Key? key,
  2. required List<TreeNode<T>> nodes,
  3. required Widget builder(
    1. BuildContext context,
    2. TreeItem<T> node
    ),
  4. bool shrinkWrap = false,
  5. ScrollController? controller,
  6. BranchLine? branchLine,
  7. EdgeInsetsGeometry? padding,
  8. bool? expandIcon,
  9. bool? allowMultiSelect,
  10. FocusScopeNode? focusNode,
  11. TreeNodeSelectionChanged<T>? onSelectionChanged,
  12. bool? recursiveSelection,
})

Creates a TreeView with hierarchical data display and interaction.

Configures a tree view widget that displays hierarchical data with support for expansion, selection, keyboard navigation, and visual styling.

Parameters:

  • key (Key?): Widget identifier for the widget tree
  • nodes (List<TreeNode
  • builder (Widget Function(BuildContext, TreeItem
  • shrinkWrap (bool, default: false): Whether to size to content
  • controller (ScrollController?, optional): Scroll controller for the tree
  • branchLine (BranchLine?, optional): Style for connecting lines
  • padding (EdgeInsetsGeometry?, optional): Padding around content
  • expandIcon (bool?, optional): Whether to show expand/collapse icons
  • allowMultiSelect (bool?, optional): Whether to allow multi-selection
  • focusNode (FocusScopeNode?, optional): Focus node for keyboard navigation
  • onSelectionChanged (TreeNodeSelectionChanged
  • recursiveSelection (bool?, optional): Whether to select children recursively

Example:

TreeView<FileItem>(
  nodes: fileTreeNodes,
  allowMultiSelect: true,
  recursiveSelection: true,
  branchLine: BranchLine.path,
  builder: (context, item) => ListTile(
    leading: Icon(item.data.isDirectory ? Icons.folder : Icons.file_copy),
    title: Text(item.data.name),
    subtitle: Text(item.data.path),
  ),
  onSelectionChanged: (selectedNodes, multiSelect, isSelected) {
    handleSelectionChange(selectedNodes, isSelected);
  },
)

Implementation

const TreeView({
  super.key,
  required this.nodes,
  required this.builder,
  this.shrinkWrap = false,
  this.controller,
  this.branchLine,
  this.padding,
  this.expandIcon,
  this.allowMultiSelect,
  this.focusNode,
  this.onSelectionChanged,
  this.recursiveSelection,
});