render method

  1. @override
void render(
  1. Rect area,
  2. Buffer buffer,
  3. RenderContext ctx
)
override

Implementation

@override
void render(Rect area, Buffer buffer, RenderContext ctx) {
  if (area.isEmpty) return;
  final isFocused = ctx.isFocused(id);

  final indicator = checked ? onIndicator : offIndicator;
  final defaultOn = Style(fg: ctx.theme.colors.success, bold: true);
  final defaultOff = Style(fg: ctx.theme.colors.muted);
  final indicatorStyle =
      checked ? (onStyle ?? defaultOn) : (offStyle ?? defaultOff);

  final labelStyle = isFocused
      ? ctx.theme.text.body.copyWith(fg: ctx.theme.colors.primary, bold: true)
      : ctx.theme.text.body;

  buffer.writeText(area.x, area.y, indicator,
      style: indicatorStyle, maxWidth: area.width);

  if (label != null) {
    final lx = area.x + indicator.length + 1;
    if (lx < area.right) {
      buffer.writeText(lx, area.y, label!,
          style: labelStyle, maxWidth: area.right - lx);
    }
  }
}