buildBox function

Widget buildBox(
  1. BuildContext context,
  2. OpenUiNode node
)

Implementation

Widget buildBox(BuildContext context, OpenUiNode node) {
  final row = node.props.string('direction') == 'row';
  final gap = node.theme.spaceOf(node.props['gap']);
  final align = node.props.string('align');
  final justify = node.props.string('justify');
  final wrap = node.props.boolean('wrap') ?? false;
  final items = _items(node, node.props['children']);
  final Widget content;
  if (row) {
    content = _row(
      _slot(items, parent: SlotParent.other, flow: false),
      theme: node.theme,
      gap: gap ?? 8,
      align: align,
      justify: justify,
      wrap: wrap,
    );
  } else {
    content = _column(
      context,
      _slot(
        items,
        parent: _flowParent(context, node, flow: gap == null),
        flow: gap == null,
      ),
      gap: gap,
      cross: _cross(align, CrossAxisAlignment.stretch),
      main: _main(justify),
      align: align,
    );
  }

  final theme = node.theme;
  final background = node.props['background'];
  final clip = node.props.has('radius');
  final radius = theme.radiusOf(node.props['radius']) ?? 0;
  final padded = Padding(
    padding: EdgeInsets.all(theme.spaceOf(node.props['padding']) ?? 0),
    child: row ? _cardHead(context, node, content) : content,
  );
  final fixedHeight = OpenUiTheme.length(node.props['height']).px != null;
  final contained = fixedHeight
      ? LayoutBuilder(
          builder: (context, constraints) => OverflowBox(
            alignment: Alignment.topCenter,
            minHeight: constraints.maxHeight,
            maxHeight: double.infinity,
            child: padded,
          ),
        )
      : padded;
  final clipped = clip
      ? ClipRRect(borderRadius: BorderRadius.circular(radius), child: contained)
      : contained;
  Widget box = Container(
    decoration: BoxDecoration(
      color: theme.bg(background),
      gradient: theme.bgGradient(background),
      borderRadius: BorderRadius.circular(radius),
      border: (node.props.boolean('border') ?? false)
          ? Border.all(color: theme.border)
          : null,
    ),
    child: clipped,
  );

  // In a media row the photo slot sets the width (CSS `!important`).
  box = _sized(context, box, node, width: !MediaRowSlot.of(context));

  final ink = theme.inkOn(background);
  if (ink == null) return box;
  return DefaultTextStyle.merge(
    style: TextStyle(color: ink),
    child: OpenUiThemeScope(theme: theme.withInk(ink), child: box),
  );
}