tree method

void tree(
  1. Map<String, dynamic> data, {
  2. String? root,
  3. TreeStyle style = TreeStyle.normal,
})

Displays a tree structure.

Convenience method for rendering tree data. For more control, use TreeComponent or Tree directly.

Parameters:

  • data: Nested map/list structure to display
  • root: Optional root label
  • style: Tree style preset (normal, rounded, ascii, etc.)

Example:

console.tree({
  'src': {
    'lib': ['main.dart', 'utils.dart'],
    'test': ['main_test.dart'],
  },
  'pubspec.yaml': null,
}, root: 'my_project');

Implementation

void tree(
  Map<String, dynamic> data, {
  String? root,
  TreeStyle style = TreeStyle.normal,
}) {
  final enumerator = switch (style) {
    TreeStyle.normal => TreeEnumerator.normal,
    TreeStyle.rounded => TreeEnumerator.rounded,
    TreeStyle.ascii => TreeEnumerator.ascii,
    TreeStyle.bullet => TreeEnumerator.bullet,
    TreeStyle.arrow => TreeEnumerator.arrow,
  };

  final component = TreeComponent(
    data: data,
    showRoot: root != null,
    rootLabel: root ?? '.',
    enumerator: enumerator,
    renderConfig: renderConfig,
  );

  for (final line in component.render().split('\n')) {
    writeln(line);
  }
  newLine();
}