'Flutter - Restart countdown timer

I'm trying to restart the countdown timer when I click on the resend code. The package I'm using is timer_count_down.

I've tried adding:

 onTap: () {
     _controller.restart();
     _submit();
 },

But it can't seem to work. here is my code:

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,
                            ),),
                          ),
                        ],
                      ))
                  ],
                ),
          ),

Is there any solutions to this?



Solution 1:[1]

Add a interval property

interval: Duration(milliseconds: 100),

and after try to restart

 onTap:: () {
   _controller.restart();
 },

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Paresh Mangukiya