FlutterCountdownTimer
FlutterCountdownTimer copied to clipboard
Restart Timer
Hi thanks for the plugin! is it possible to restart the time or countdown to original endTime?
You can restart it by modifying endTime.
setState(() {
endTime = newEndTime;
});
setState(() { endTime = newEndTime; }); does not reset either
setState(() { endTime = newEndTime; }); does not reset either
If a controller is used
controller.endTime = newEndTime;
controller.start();
setState(() { endTime = newEndTime; }); does not reset either
If a controller is used
controller.endTime = newEndTime; controller.start();
Doesn't work
You can try this... it worked for me.
` setState(() { // new endTime from TextField endTime = DateTime.now().millisecondsSinceEpoch + Duration(seconds: int.parse(timeTextCtrl.text)) .inMilliseconds; controller = CountdownTimerController(endTime: endTime, onEnd: onEnd); controller.start();
});`
You can try this... it worked for me.
` setState(() { // new endTime from TextField endTime = DateTime.now().millisecondsSinceEpoch + Duration(seconds: int.parse(timeTextCtrl.text)) .inMilliseconds; controller = CountdownTimerController(endTime: endTime, onEnd: onEnd); controller.start();
});`
work for me to, is so good
most generic
action: () {
setState(() {
endTime = DateTime.now().millisecondsSinceEpoch +
Duration(seconds: 10).inMilliseconds;
controller = CountdownTimerController(endTime: endTime);
controller.start();
});
},
countdownController.value = Duration(seconds: 5).inMilliseconds;
countdownController.start();
https://github.com/wuweijian1997/FlutterCountdownTimer/pull/40#issuecomment-839682919