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}) {
  int hour = (time / 3600).floor();
  int minute = ((time - 3600 * hour) / 60).floor();
  int second = (time - 3600 * hour - 60 * minute);

  String timeText = "";

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

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

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

  return timeText;
}