defaultTreeNodeBuilder static method

Widget defaultTreeNodeBuilder(
  1. BuildContext context,
  2. TreeViewNode<Object?> node,
  3. AnimationStyle toggleAnimationStyle
)

Default builder for the widget representing a given TreeViewNode in the tree.

Used by TreeView.treeNodeBuilder.

This will return a Row containing the toString of TreeViewNode.content. If the TreeViewNode is a parent of additional nodes, an arrow icon will precede the content, and will trigger an expand and collapse animation when tapped based on the TreeView.toggleAnimationStyle.

Implementation

static Widget defaultTreeNodeBuilder(
  BuildContext context,
  TreeViewNode<Object?> node,
  AnimationStyle toggleAnimationStyle,
) {
  final Duration animationDuration =
      toggleAnimationStyle.duration ?? TreeView.defaultAnimationDuration;
  final Curve animationCurve =
      toggleAnimationStyle.curve ?? TreeView.defaultAnimationCurve;
  final int index = TreeViewController.of(context).getActiveIndexFor(node)!;
  return Padding(
    padding: const EdgeInsets.all(8.0),
    child: Row(children: <Widget>[
      // Icon for parent nodes
      TreeView.wrapChildToToggleNode(
        node: node,
        child: SizedBox.square(
          dimension: 30.0,
          child: node.children.isNotEmpty
              ? AnimatedRotation(
                  key: ValueKey<int>(index),
                  turns: node.isExpanded ? 0.25 : 0.0,
                  duration: animationDuration,
                  curve: animationCurve,
                  // Renders a unicode right-facing arrow. >
                  child: const Icon(IconData(0x25BA), size: 14),
                )
              : null,
        ),
      ),
      // Spacer
      const SizedBox(width: 8.0),
      // Content
      Text(node.content.toString()),
    ]),
  );
}