[英]Flutter - Restart countdown timer
当我点击重新发送代码时,我试图重新启动倒数计时器。 我使用的 package 是timer_count_down 。
我试过添加:
onTap: () {
_controller.restart();
_submit();
},
但这似乎行不通。 这是我的代码:
final CountdownController _controller =
new CountdownController(autoStart: true);
@override
Widget build(BuildContext context) {
return Countdown(
seconds: 40,
build: (_, double time) =>
Column(
children: [
Text(time.toString(),
style: TextStyle(
color: Theme.of(context).primaryColor,
),
),
SizedBox(height: 30,),
Visibility(
visible: time == 0,
child: Column(
children: [
Text('Haven\'t recieved the code?',
style: TextStyle(
color: Colors.grey
),
),
SizedBox(height: 10,),
InkWell(
onTap: () {
_controller.restart();
_submit();
},
child: Text('Resend code',
style: TextStyle(
color: Theme.of(context).primaryColor,
fontWeight: FontWeight.bold,
decoration: TextDecoration.underline,
),),
),
],
))
],
),
),
有什么解决办法吗?
通过使用您提供的代码和 package(由项目提供) github.com/DizoftTeam/simple_count_down/blob/master/example/lib/main.dart的示例代码,我已经能够重现您的问题。
在这两种情况下,这个问题都是由于没有将 CountdownController 分配给 Countdown 小部件引起的。
您应该将以下代码行添加到倒计时小部件: controller: _controller,
它应该是这样的:
return Countdown(
controller: _controller,
seconds: 40,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.