defaultTreeNodeBuilder static method

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

Returns the default tree row for a given TreeSliverNode.

Used by TreeSliver.treeNodeBuilder.

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

Implementation

static Widget defaultTreeNodeBuilder(
  BuildContext context,
  TreeSliverNode<Object?> node,
  AnimationStyle toggleAnimationStyle
) {
  final Duration animationDuration = toggleAnimationStyle.duration
    ?? TreeSliver.defaultAnimationDuration;
  final Curve animationCurve = toggleAnimationStyle.curve
    ?? TreeSliver.defaultAnimationCurve;
  final int index = TreeSliverController.of(context).getActiveIndexFor(node)!;
  return Padding(
    padding: const EdgeInsets.all(8.0),
    child: Row(children: <Widget>[
      // Icon for parent nodes
      TreeSliver.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()),
    ]),
  );
}