I'm trying to get the following format from an int: ss:m
(s = seconds, m = milliseconds) from a countdown timer. If there are minutes, the format should be mm:ss:m
.
Here's my code:
final int currentTime = 100; // 10 seconds
final Duration duration = Duration(milliseconds: 100);
Timer.periodic(duration, (Timer _timer) {
if (currentTime <= 0) {
_timer.cancel();
} else {
currentTime--;
print(currentTime);
}
});
I tried adding currentTime
to a Duration
as milliseconds but it didn't give me the desired results. What am I doing wrong and how can I get it to the correct format?