toString function
将 Duration 转换为形如 102:10:04 格式的字符串 此函数和 Duration toString 不同在于忽略秒以后的数值
toString(Duration(seconds: 100)) == '01:40'
Implementation
String toString(Duration duration) {
final sign = duration.inSeconds < 0 ? '-' : '';
var hours = '';
final h = duration.inHours.abs();
if (h > 0) hours = '$h:';
final twoDigitMinutes =
_twoDigits(duration.inMinutes.remainder(Duration.minutesPerHour).abs());
final twoDigitSeconds =
_twoDigits(duration.inSeconds.remainder(Duration.secondsPerMinute).abs());
return '$sign$hours$twoDigitMinutes:$twoDigitSeconds';
}