formatQuotaBadge function
String
formatQuotaBadge({
- required String shortName,
- ProviderQuota? quota,
- required DateTime now,
Status-badge string for the ACTIVE provider: [OR $48/$150 · 11d].
Cold cache renders [OR …]; unmetered providers render nothing
(silent — they must not crowd the status line, AC7).
Implementation
String formatQuotaBadge({
required String shortName,
ProviderQuota? quota,
required DateTime now,
}) {
if (quota == null) return '[$shortName …]';
if (quota.isUnmetered || quota.unit == QuotaUnit.unmetered) return '';
final isCurrency = quota.unit == QuotaUnit.currencyUsd;
String? short(double? v) =>
v == null ? null : '${isCurrency ? r'$' : ''}${_trimNumber(v, 0)}';
final used = short(quota.used);
final limit = short(quota.limit);
final ratio = used == null && limit == null
? 'unlimited'
: limit == null
? '${used ?? "…"}/no cap'
: '$used/$limit';
final reset = formatQuotaReset(quota.resetsAt, now);
return '[$shortName $ratio${reset.isEmpty ? '' : ' · $reset'}]';
}