calculateContentWidth<T> static method
Calculate the total content width of all nodes
Implementation
static double calculateContentWidth<T>({
required List<Node<T>> nodes,
required FolderViewTextTheme textTheme,
double linePaintWidth = 20.0,
double iconSize = 20.0,
double spacing = 8.0,
double leftPadding = 0.0,
double rightPadding = 16.0,
double maxWidth = double.infinity,
}) {
double maxNodeWidth = 0.0;
for (var node in nodes) {
final nodeWidth = _calculateNodeWidth(
node: node,
textTheme: textTheme,
depth: 0,
linePaintWidth: linePaintWidth,
iconSize: iconSize,
spacing: spacing,
rightPadding: rightPadding,
);
if (nodeWidth > maxNodeWidth) {
maxNodeWidth = nodeWidth;
}
// Recursively check children if expanded
if (node.isExpanded && node.children.isNotEmpty) {
final childrenWidth = calculateContentWidth(
nodes: node.children,
textTheme: textTheme,
linePaintWidth: linePaintWidth,
iconSize: iconSize,
spacing: spacing,
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);
}