I have created a countdown timer that will countdown from a user inputted duration, in minutes.
The countdown timer technically works, but only the minutes are being shown counting down. The seconds remain at :00 the entire time.
How can I get the seconds to also display as part of the countdown timer?
Here is the relevant code, excerpted from a longer file. I can include more if needed.
The individual pieces of code are broken down as follows:
First, I have a class that actually displays the timer text and allows it to be styled:
class Countdown extends AnimatedWidget {
Countdown({ Key key, this.animation }) : super(key: key, listenable: animation);
Animation<int> animation;
@override
build(BuildContext context){
Duration clockTimer = Duration(seconds: animation.value*60);
String timerText = '${clockTimer.inMinutes.remainder(60).toString()}:${(clockTimer.inSeconds.remainder(60) % 60).toString().padLeft(2, '0')}';
return Text(
"$timerText",
style: TextStyle(
fontSize: 110,
color: Theme.of(context).primaryColor,
),
);
}
}
I have an animation controller as follows:
AnimationController _controller;
@override
void dispose(){
_controller.dispose();
super.dispose();
}
void initState() {
super.initState();
@override
_controller = AnimationController(
vsync: this,
duration: Duration(minutes: gameData.levelClock) // gameData.levelClock is a user entered number elsewhere in the applciation
);
}
And finally here is the part of the code that calls the Countdown widget:
Countdown(
animation: StepTween(
begin: gameData.levelClock, // THIS IS A USER ENTERED NUMBER
end: 0,
).animate(_controller),
)