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 apTheme = theme.accentPanelTheme;

  final color = accentColor ?? apTheme?.accentColor ?? theme.primary;
  final width = accentWidth ?? apTheme?.accentWidth ?? 1;
  final char = accentChar ?? '│';
  final bg = background ?? apTheme?.background;
  final fg = foreground ?? apTheme?.foreground ?? theme.onSurface;
  final pad = padding ?? apTheme?.padding ?? const EdgeInsets.only(left: 1);

  // Build the accent stripe
  final accentStyle = _copyStyle(null)..foreground(color);
  final accentText = List.filled(width, char).join();
  final accent = Text(accentText, style: accentStyle);

  // Build the content
  Widget content;
  final isCollapsible = expanded != null;

  if (title != null) {
    final tStyle = _copyStyle(titleStyle ?? theme.titleSmall)
      ..foreground(fg)
      ..bold();

    Widget header;
    if (isCollapsible) {
      final chevronStyle = _copyStyle(theme.labelMedium)
        ..foreground(theme.muted);
      header = GestureDetector(
        onTap: () => onExpandChanged?.call(!expanded!),
        child: Row(
          gap: 1,
          children: [
            Text(expanded! ? 'v' : '>', style: chevronStyle),
            Text(title!, style: tStyle),
          ],
        ),
      );
    } else {
      header = Text(title!, style: tStyle);
    }

    if (isCollapsible && !expanded!) {
      content = header;
    } else {
      content = Column(gap: 1, children: [header, child]);
    }
  } else {
    content = child;
  }

  // Wrap content with padding and optional background
  Widget body = Padding(padding: pad, child: content);
  if (bg != null) {
    body = Frame(background: bg, child: body);
  }
  if (fg != theme.onSurface) {
    body = Frame(foreground: fg, child: body);
  }

  // Compose accent + body
  final children = side == AccentSide.left
      ? [accent, Expanded(child: body)]
      : [Expanded(child: body), accent];

  return Row(children: children);
}