0

I am trying to show countdown timer using this resource: https://stackoverflow.com/a/64312145/13240914:

TweenAnimationBuilder<Duration>(
  duration: Duration(minutes: 3),
  tween: Tween(begin: Duration(minutes: 3), end: Duration.zero),
  onEnd: () {
    print('Timer ended');
  },
  builder: (BuildContext context, Duration value, Widget? child) {
    final minutes = value.inMinutes;
    final seconds = value.inSeconds % 60;
    return Padding(
      padding: const EdgeInsets.symmetric(vertical: 5),
      child: Text('$minutes:$seconds',
               textAlign: TextAlign.center,
               style: TextStyle(
               color: Colors.black,
               fontWeight: FontWeight.bold,
               fontSize: 30)));
    }),

The problem is when duration is still running, I would like to update duration. For example when user click a button, the duration will change from 10 to 20 seconds, but the duration doesn't change to 20 seconds at all... it keeps going to count 10 seconds. Is there a way to update the value of Duration when the duration is still running ?

wahyu
  • 1,679
  • 5
  • 35
  • 73

1 Answers1

0

you can't jump on a new value using TweenAnimationBuilder. you have to use explicit animation for this. check this out: How to choose which Flutter Animation Widget is right for you?

reza
  • 1,354
  • 1
  • 7
  • 25
  • please include the relevant quotations from the URL you've provided, as the answers should be valid for a long period of time while the URL may break. – Adnan Jan 09 '22 at 09:21