getTextFromSeconds static method

String getTextFromSeconds({
  1. int time = 0,
  2. bool withZeros = true,
  3. bool withHours = true,
  4. bool withMinutes = true,
  5. bool withSpace = true,
})

Implementation

static String getTextFromSeconds(
    {int time = 0,
    bool withZeros = true,
    bool withHours = true,
    bool withMinutes = true,
    bool withSpace = true}) {
  final int hour = (time / 3600).floor();
  final int minute = ((time - 3600 * hour) / 60).floor();
  final int second = (time - 3600 * hour - 60 * minute);

  String timeText = '';

  if (withHours && hour != 0) {
    if (hour < 10 && withZeros) {
      timeText += '0$hour${withSpace ? " : " : ":"}';
    } else {
      timeText += hour.toString() + (withSpace ? ' : ' : '');
    }
  }

  if (withMinutes) {
    if (minute < 10 && withZeros) {
      timeText += '0$minute${withSpace ? ' : ' : ":"}';
    } else {
      timeText += minute.toString() + (withSpace ? ' : ' : '');
    }
  }

  if (second < 10 && withZeros) {
    timeText += '0$second';
  } else {
    timeText += second.toString();
  }

  return timeText;
}