【发布时间】:2020-04-19 15:58:05
【问题描述】:
我创建了一个倒数计时器,它将从用户输入的持续时间开始倒计时,以分钟为单位。
倒数计时器在技术上有效,但仅显示分钟数。秒数始终保持在 :00。
如何让秒数也显示为倒计时的一部分?
这里是相关代码,摘自一个较长的文件。如果需要,我可以添加更多内容。
各段代码分解如下:
首先,我有一个实际显示计时器文本并允许对其进行样式设置的类:
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,
),
);
}
}
我有一个动画控制器如下:
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
);
}
最后是调用 Countdown 小部件的代码部分:
Countdown(
animation: StepTween(
begin: gameData.levelClock, // THIS IS A USER ENTERED NUMBER
end: 0,
).animate(_controller),
)
感谢您提供的任何帮助。
【问题讨论】:
标签: flutter dart flutter-animation