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 base = ctx.theme.text.body;
  final style = isFocused
      ? base.copyWith(fg: ctx.theme.colors.primary, bold: true)
      : base;
  final label = selected == null ? placeholder : _label(selected as T);
  final arrow = state.open ? '▲' : '▼';
  buffer.writeText(area.x, area.y, '$label $arrow',
      style: style, maxWidth: area.width);

  if (state.open) {
    final h = (options.length + 2).clamp(3, maxDropdownHeight + 2);
    final dropArea = Rect(area.x, area.y + 1, area.width, h);
    ctx.drawOverlay(
      _DropdownPanel<T>(
        options: options,
        highlightedIndex: state.highlightedIndex,
        display: _label,
      ),
      dropArea,
    );
  }
}