formatCountOrNull static method

String? formatCountOrNull(
  1. int? count, {
  2. int cap = 99,
  3. String overflowLabel = '99+',
})

Formats count as a badge string while capping overflow; returns null when the count is absent or zero so callers can skip rendering.

Implementation

static String? formatCountOrNull(int? count,
    {int cap = 99, String overflowLabel = '99+'}) {
  if (count == null || count <= 0) {
    return null;
  }
  if (count > cap) {
    return overflowLabel;
  }
  return count.toString();
}