render method
Implementation
@override
void render(Rect area, Buffer buffer, RenderContext ctx) {
if (area.isEmpty) return;
final isFocused = ctx.isFocused(id);
final borderStyle = border ??
(isFocused ? ctx.theme.borders.focusedStyle : ctx.theme.borders.style);
final stroke = isFocused
? ctx.theme.borders.focusedStrokeStyle.withFg(ctx.theme.colors.primary)
: ctx.theme.borders.strokeStyle;
final hasBorder = borderStyle != BorderStyle.none && area.height >= 3;
final inner = hasBorder ? area.insetAll(1) : area;
if (hasBorder) {
_drawBorder(area, buffer, borderStyle, stroke);
}
final v = state?.value ?? value;
final cur = state?.cursor ?? value.length;
final isValid = validate?.call(v) ?? true;
final textStyle = isFocused
? (focusedStyle ?? Style.none)
: (unfocusedStyle ?? ctx.theme.text.body);
final display = v.isEmpty ? placeholder : (obscure ? '*' * v.length : v);
final displayStyle = v.isEmpty
? ctx.theme.text.caption
: (isValid
? textStyle
: textStyle.copyWith(fg: ctx.theme.colors.error));
if (!inner.isEmpty) {
buffer.writeText(inner.x, inner.y, display,
style: displayStyle, maxWidth: inner.width);
if (isFocused && cur <= v.length) {
final cx = inner.x + cur;
if (cx < inner.right) {
final c = cur < v.length ? v[cur] : ' ';
final ch = obscure && cur < v.length ? '*' : c;
buffer.setChar(cx, inner.y, ch, style: const Style(reverse: true));
}
}
}
}