debounce method
void
debounce([
- dynamic callback
Implementation
void debounce([callback]) {
void exec() {
callback != null ? callback() : this.callback(args);
}
void clear() {
timer = null;
}
/// cancel the previous timer if debounce is still being called before the delay period is over
timer?.cancel();
/// if atBegin is true, 'exec' has to executed the first time debounce gets called
if (atBegin && timer == null) {
exec();
}
/// schedule a new call after delay time
timer = Timer(delay, atBegin ? clear : exec);
}