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
)
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();
}
// 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();
1 comments:
Click here for commentsNo more live link in this comments field
ConversionConversion EmoticonEmoticon