formatSheenDuration function Music
A time as a player shows it: 1:30, 0:05, 1:02:03, or -2:27 for time left.
Implementation
String formatSheenDuration(Duration d) {
final neg = d.isNegative && d.inSeconds != 0;
final s = d.inSeconds.abs();
final h = s ~/ 3600, m = (s % 3600) ~/ 60, sec = s % 60;
final body = h > 0
? '$h:${m.toString().padLeft(2, '0')}:${sec.toString().padLeft(2, '0')}'
: '$m:${sec.toString().padLeft(2, '0')}';
return neg ? '-$body' : body;
}