getFormatter static method

String Function(Duration) getFormatter({
  1. bool showHours = true,
  2. bool showMinutes = true,
  3. bool showSeconds = true,
  4. bool showMilliseconds = false,
  5. String? customPattern,
})

Get the most appropriate format for a given duration

Implementation

static String Function(Duration) getFormatter({
  bool showHours = true,
  bool showMinutes = true,
  bool showSeconds = true,
  bool showMilliseconds = false,
  String? customPattern,
}) {
  if (customPattern != null) {
    return (duration) => formatCustom(duration, customPattern);
  }

  if (showMilliseconds) {
    return formatWithMilliseconds;
  }

  if (showHours && showMinutes && showSeconds) {
    return formatHHMMSS;
  } else if (showMinutes && showSeconds) {
    return formatMMSS;
  } else if (showSeconds) {
    return formatSS;
  } else {
    return formatSmart;
  }
}