sliderBar method
void
sliderBar(})
Renders a slider bar with head indicator.
The trailing label is built from value, unit, and showPercent:
| unit | showPercent | Display |
|---|---|---|
| (none) | false | 30 |
% |
false | 30% |
s |
false | 30s |
| (none) | true | 30 (10%) |
s |
true | 30s (10%) |
When value is null, falls back to showing pct% if showPercent
is true, or nothing otherwise.
Implementation
void sliderBar(
double ratio, {
int width = 28,
String filledChar = '█',
String emptyChar = '·',
String? headChar,
bool showPercent = false,
num? value,
String unit = '',
}) {
final clamped = ratio.clamp(0.0, 1.0);
final filled = (clamped * width).round();
final pct = (clamped * 100).round();
final filledPart = '${theme.accent}${filledChar * filled}${theme.reset}';
final head = headChar ?? (pct < 50 ? '◉' : '●');
final emptyPart =
'${theme.dim}${emptyChar * (width - filled)}${theme.reset}';
String label;
if (value != null) {
final v = value;
final display =
v == v.roundToDouble() ? v.toInt().toString() : v.toString();
final valuePart = '$display$unit';
final pctPart = showPercent ? ' ($pct%)' : '';
label = ' ${theme.dim}$valuePart$pctPart${theme.reset}';
} else if (showPercent) {
label = ' ${theme.dim}$pct%${theme.reset}';
} else {
label = '';
}
gutterLine('$filledPart${theme.accent}$head${theme.reset}$emptyPart$label');
}