tree method
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 displayroot: Optional root labelstyle: 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();
}