wrapChildToToggleNode static method

Widget wrapChildToToggleNode({
  1. required TreeViewNode<Object?> node,
  2. required Widget child,
})

A wrapper method for triggering the expansion or collapse of a TreeViewNode.

Use as part of TreeView.defaultTreeNodeBuilder to wrap the leading icon of parent TreeViewNodes such that tapping on it triggers the animation.

If defining your own TreeView.treeNodeBuilder, this method can be used to wrap any part, or all, of the returned widget in order to trigger the change in state for the node when tapped.

The gesture uses HitTestBehavior.translucent, so as to not conflict with any TreeRow.recognizerFactories or other interactive content in the TreeRow.

Implementation

static Widget wrapChildToToggleNode({
  required TreeViewNode<Object?> node,
  required Widget child,
}) {
  return Builder(builder: (BuildContext context) {
    return GestureDetector(
      behavior: HitTestBehavior.translucent,
      onTap: () {
        TreeViewController.of(context).toggleNode(node);
      },
      child: child,
    );
  });
}