calculateMaxContentWidth<T> static method
double
calculateMaxContentWidth<T>({
- required BuildContext context,
- required List<
Node< nodes,T> > - 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 the maximum content width from ALL nodes (including collapsed children).
Recursively traverses the entire tree to find the widest node, ensuring stable width regardless of expand/collapse state.
Implementation
static double calculateMaxContentWidth<T>({
required BuildContext context,
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,
}) {
final linePaintWidth = expandIconTheme.width +
expandIconTheme.padding.horizontal +
expandIconTheme.margin.horizontal;
// Get the base text style from theme to include letterSpacing etc.
final baseTextStyle = Theme.of(context).textTheme.bodyMedium;
double maxNodeWidth = 0.0;
void traverse(List<Node<T>> nodeList, int depth) {
for (final node in nodeList) {
final nodeWidth = _calculateNodeWidth(
node: node,
depth: depth,
folderTheme: folderTheme,
parentTheme: parentTheme,
childTheme: childTheme,
expandIconTheme: expandIconTheme,
linePaintWidth: linePaintWidth,
rightPadding: rightPadding,
baseTextStyle: baseTextStyle,
);
if (nodeWidth > maxNodeWidth) {
maxNodeWidth = nodeWidth;
}
// Recurse into children regardless of expanded state
if (node.children.isNotEmpty) {
traverse(node.children, depth + 1);
}
}
}
traverse(nodes, 0);
final totalWidth = leftPadding + maxNodeWidth;
return totalWidth.clamp(0.0, maxWidth);
}