formatTime method
Format seconds as m:ss or h:mm:ss depending on total duration.
Implementation
String formatTime(double seconds) {
if (seconds.isNaN || seconds.isInfinite || seconds < 0) return '0:00';
final total = Duration(seconds: seconds.toInt());
final h = total.inHours;
final m = total.inMinutes.remainder(60);
final s = total.inSeconds.remainder(60);
if (h > 0) {
return '$h:${m.toString().padLeft(2, '0')}:${s.toString().padLeft(2, '0')}';
}
return '$m:${s.toString().padLeft(2, '0')}';
}