Created
October 16, 2024 20:57
-
-
Save urusaich/e00e0bad0f1d11fcaad9fac21a510471 to your computer and use it in GitHub Desktop.
Time remains
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String remainsText( | |
Duration? remains, { | |
String leading = ' (', | |
String trailing = ')', | |
bool padMinutes = true, | |
bool padSeconds = true, | |
}) { | |
if (remains == null) { | |
return ''; | |
} | |
final seconds = remains.inSeconds; | |
final minutes = remains.inMinutes; | |
final s = seconds.remainder(Duration.secondsPerMinute).abs(); | |
final minutesText = minutes > 9 || !padMinutes ? '$minutes' : '0$minutes'; | |
final secondsText = s > 9 || !padSeconds ? '$s' : '0$s'; | |
return '$leading$minutesText:$secondsText$trailing'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment