Countdown timer in flutter | Restartable timer in flutter



RestartableTimer class


1- Set RestartableTimer
2- Set Duration
3. Set Callback


The restartable timer implements Timer. It restarts from its initial position and can be restart any number of time. It provide a callback when given time passed.



import 'package:async/async.dart';

RestartableTimer(
  Duration _givenTime,
  ZoneCallback _zoneCallback
)


Example-

Method call when timer finishes its execution


_onTimerFinished() {
     // TODO: Perform some action
     print('Timer Finished');
}

RestartableTimer _restartTimer = RestartableTimer(Duration(seconds: 10),_onTimerFinished);

onPressed(){
   _restartTimer.reset();
}


To reset the timer

 _restartTimer.reset();

To cancel the timer

 _restartTimer.cancel();





Previous
Next Post »

1 comments:

Click here for comments
Anonymous
admin
September 24, 2020 at 2:54 AM ×

No more live link in this comments field

Congrats bro Anonymous you got PERTAMAX...! hehehehe...
Reply
avatar

ConversionConversion EmoticonEmoticon

:)
:(
=(
^_^
:D
=D
=)D
|o|
@@,
;)
:-bd
:-d
:p
:ng