toTimeString method

String toTimeString()

Converts the duration to a formatted time string (MM:SS).

Example:

Duration(seconds: 75).toTimeString(); // "01:15"

Implementation

String toTimeString() {
  int totalSeconds = inSeconds;
  int minutes = totalSeconds ~/ 60;
  int seconds = totalSeconds % 60;
  return '${minutes.toString().padLeft(2, '0')}:'
      '${seconds.toString().padLeft(2, '0')}';
}