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 ?