simplify function

IrNode simplify(
  1. IrNode node
)

Removes structural wrappers that Flutter needs but a designer doesn't:

  • Padding(child: Column(...)) → a Column frame with padding.
  • SizedBox(width: 100, child: Foo()) → Foo with a fixed width.

A wrapper is only folded into its child when the result renders identically: same size on both axes and same child placement.

Implementation

IrNode simplify(IrNode node) {
  if (node is! IrFrame) return node;
  node.children = [for (final c in node.children) simplify(c)];
  return _fold(node) ?? node;
}