calculateContentWidth<T> static method

double calculateContentWidth<T>({
  1. required List<Node<T>> nodes,
  2. required FolderNodeTheme folderTheme,
  3. required ParentNodeTheme parentTheme,
  4. required ChildNodeTheme childTheme,
  5. required ExpandIconTheme expandIconTheme,
  6. double leftPadding = 0.0,
  7. double rightPadding = 16.0,
  8. double maxWidth = double.infinity,
})

Calculate the total content width of all nodes

Implementation

static double calculateContentWidth<T>({
  required List<Node<T>> nodes,
  required FolderNodeTheme folderTheme,
  required ParentNodeTheme parentTheme,
  required ChildNodeTheme childTheme,
  required ExpandIconTheme expandIconTheme,
  double leftPadding = 0.0,
  double rightPadding = 16.0,
  double maxWidth = double.infinity,
}) {
  // Calculate line width based on expand icon size
  final linePaintWidth = expandIconTheme.width +
      expandIconTheme.padding.horizontal +
      expandIconTheme.margin.horizontal;

  double maxNodeWidth = 0.0;

  for (var node in nodes) {
    final nodeWidth = _calculateNodeWidth(
      node: node,
      folderTheme: folderTheme,
      parentTheme: parentTheme,
      childTheme: childTheme,
      expandIconTheme: expandIconTheme,
      depth: 0,
      linePaintWidth: linePaintWidth,
      rightPadding: rightPadding,
    );
    if (nodeWidth > maxNodeWidth) {
      maxNodeWidth = nodeWidth;
    }

    // Recursively check children if expanded
    if (node.isExpanded && node.children.isNotEmpty) {
      final childrenWidth = calculateContentWidth(
        nodes: node.children,
        folderTheme: folderTheme,
        parentTheme: parentTheme,
        childTheme: childTheme,
        expandIconTheme: expandIconTheme,
        leftPadding: 0.0, // Children don't need extra left padding
        rightPadding: rightPadding,
        maxWidth: maxWidth,
      );
      // Add one level of indentation for children
      final adjustedChildWidth = childrenWidth + linePaintWidth;
      if (adjustedChildWidth > maxNodeWidth) {
        maxNodeWidth = adjustedChildWidth;
      }
    }
  }

  // Add left and right padding to the final width
  final totalWidth = leftPadding + maxNodeWidth;
  return totalWidth.clamp(0.0, maxWidth);
}