Jack Spicy
Jack Spicy

Reputation: 93

How to update the duration of CircularCountDown widget more than one time

I need to refresh the duration of my CircularCountDownTimer() more than one time.

        child: CircularCountDownTimer(
          width: MediaQuery.of(context).size.width / 2,
          height: MediaQuery.of(context).size.height / 2,
          duration: _duration,
          fillColor: _fillColor,
          ringColor: Colors.green,
          controller: _controller,
          backgroundColor: Colors.white54,
          strokeWidth: 50.0,
          strokeCap: StrokeCap.butt,
          isTimerTextShown: true,
          isReverse: true,
          onComplete: () {
            setState(() {
              _fillColor = Colors.purple;
              _controller.restart(duration: 90); // here I update the duration, but I need to update it one more time. 
            });
          },
          textStyle: TextStyle(fontSize: 50.0, color: Colors.black),
        ),

Upvotes: 1

Views: 64

Answers (1)

Akif
Akif

Reputation: 7640

You need to define a duration variable. Then you can change it in a method like this:

int duration = 10; // i.e.

void addDuration() {
  setState(() {
    duration += 2;
    //In my scenario, I added 2 more seconds.
  });
}

Now, you can restart your controller with the newest duration:

_controller.restart(duration: duration);

Upvotes: 1

Related Questions