toHumanizedString method
Converts the Duration into a human-friendly string in the format:
HH:MM:SSif hours are presentMM:SSif no hours
Minutes and seconds are zero-padded if necessary.
Implementation
String toHumanizedString() {
final seconds = '${inSeconds % 60}'.padLeft(2, '0');
String minutes = '${inMinutes % 60}';
if (inHours > 0 || inMinutes == 0) {
minutes = minutes.padLeft(2, '0');
}
String value = '$minutes:$seconds';
if (inHours > 0) {
value = '$inHours:$minutes:$seconds';
}
return value;
}