flattenGroups<T> function
Flattens nodes into visible rows, skipping the contents of collapsed
groups.
Implementation
List<GridRow<T>> flattenGroups<T>(
List<GroupNode<T>> nodes,
GroupExpansionState expansion, {
Set<String> loadingPaths = const {},
int Function(T row)? sourceIndexOf,
}) {
final out = <GridRow<T>>[];
void walk(List<GroupNode<T>> level) {
for (final node in level) {
final expanded = expansion.isExpanded(node.path);
out.add(GroupGridRow<T>(
index: out.length,
depth: node.depth,
node: node,
expanded: expanded,
loading: loadingPaths.contains(node.path),
));
if (!expanded) continue;
// An open group whose rows have not arrived yet shows its header and
// nothing under it, rather than claiming to be empty.
if (!node.loaded) continue;
if (node.isLeafGroup) {
for (final row in node.rows) {
out.add(DataGridRow<T>(
index: out.length,
data: row,
sourceIndexOf: sourceIndexOf,
depth: node.depth + 1,
));
}
} else {
walk(node.children);
}
}
}
walk(nodes);
return out;
}