Tree class

A fluent builder for creating styled trees (lipgloss v2 parity).

This mirrors charm.land/lipgloss/v2/tree behavior:

  • Per-node hide + child filtering
  • Auto-parenting unnamed subtrees to previous siblings
  • Separate enumerator/indenter functions + styles
  • Multiline items and mixed prefix widths are aligned A component for rendering hierarchical tree structures.

The Tree component supports:

  • Nested children with arbitrary depth.
  • Custom enumerators (branch characters) like bullets, numbers, or custom strings.
  • Per-item and per-enumerator styling.
  • Automatic indentation and branch line rendering.

Example:

final tree = Tree(['Root'])
  .children([
    Tree(['Child 1']),
    Tree(['Child 2']).children([
      Tree(['Grandchild']),
    ]),
  ]);

print(tree.render());
Inheritance
Implemented types
Available extensions

Constructors

Tree({RenderConfig renderConfig = const RenderConfig(), bool showRoot = true})

Properties

childrenNodes → Iterable<TreeNode>
no setteroverride
hashCode → int
The hash code for this object.
no setterinherited
hidden → bool
no setteroverride
lineCount → int
Number of lines in the rendered output.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
value → String
no setteroverride

Methods

child(Object? item) → Tree
children(List items) → Tree
childrenAll(List items) → Tree
enumerator(Object enumerator) → Tree
enumeratorFunc(TreeEnumeratorFunc fn) → Tree
enumeratorStyle(Style style) → Tree
enumeratorStyleFunc(TreeNodeStyleFunc fn) → Tree
Sets the enumeration style function. Use this for conditional styling.
hide(bool value) → Tree
indenterFunc(TreeIndenterFunc fn) → Tree
indenterStyle(Style style) → Tree
indenterStyleFunc(TreeNodeStyleFunc fn) → Tree
Sets the indentation style function. Use this for conditional styling.
init() → Cmd?
Returns an optional command to execute on program startup.
inherited
itemStyle(Style style) → Tree
itemStyleFunc(TreeNodeStyleFunc fn) → Tree
Sets the item style function. Use this for conditional styling.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
offset(int start, [int end = 0]) → Tree
render() → String
Renders the component as a styled string.
override
root(Object? label) → Tree
rootStyle(Style style) → Tree
showRoot(bool value) → Tree
toString() → String
A string representation of this object.
inherited
update(Msg msg) → (ViewComponent, Cmd?)
Updates the component state in response to a message.
inherited
view() → String
Renders the current model state for display.
inherited
width(int width) → Tree
writelnTo(Console io) → void

Available on DisplayComponent, provided by the DisplayComponentExtension extension

Renders the component and writes it to the console.

Operators

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