我正在try 建立一个倒计时小工具.目前,我已经让这个 struct 运转起来了.我只为倒计时本身而苦苦挣扎.我使用倒计时插件try 了这种方法:
class _Countdown extends State<Countdown> {
int val = 3;
void countdown(){
CountDown cd = new CountDown(new Duration(seconds: 4));
cd.stream.listen((Duration d) {
setState((){
val = d.inSeconds;
});
});
}
@override
build(BuildContext context){
countdown();
return new Scaffold(
body: new Container(
child: new Center(
child: new Text(val.toString(), style: new TextStyle(fontSize: 150.0)),
),
),
);
}
}
然而,值的变化非常奇怪,一点也不平滑.它开始抽搐.是否有其他方法或解决方案?