build method

  1. @override
Widget build(
  1. BuildContext context
)
override

Describes the part of the UI represented by this widget.

Implementation

@override
Widget build(BuildContext context) {
  final theme = ThemeScope.of(context);
  final headerStyle = _copyStyle(titleStyle ?? theme.titleSmall)
    ..foreground(foreground ?? theme.onSurface);
  final contentStyle = _copyStyle(bodyStyle ?? theme.bodyMedium)
    ..foreground(foreground ?? theme.onSurface);

  final hasHeader = title != null || actions.isNotEmpty;
  final header = hasHeader
      ? Row(
          gap: 1,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            if (title != null) Text(title!, style: headerStyle),
            if (actions.isNotEmpty) Spacer(),
            if (actions.isNotEmpty) Row(gap: 1, children: actions),
          ],
        )
      : null;

  final body = bodyStyle == null
      ? child
      : Frame(style: contentStyle, child: child);

  final content = Column(
    gap: hasHeader ? 1 : 0,
    children: [
      if (header != null) header,
      if (header != null) Divider(style: Style().foreground(theme.border)),
      body,
    ],
  );

  return Frame(
    padding: padding ?? const EdgeInsets.all(1),
    margin: margin,
    background: background ?? theme.surface,
    border: border ?? Border.rounded,
    borderColor: borderColor ?? theme.border,
    child: content,
  );
}