call method

void call()

Accumulates a function call and triggers execution if the required call count is met.

Each call to this method increments the call count. If the required number of calls is met within the specified _duration, the _runnable function is executed. If the _requiredCallCount is not met within the duration, the accumulator is reset, and the execution is not triggered.

Implementation

void call() {
  if (_resetTimer == null) {
    _resetTimer = Timer(_duration, () {
      _callCounter = 0;
      _resetTimer = null;
    });
  }
  _callCounter++;
  if (_callCounter == _requiredCallCount) {
    _resetTimer?.cancel();
    _resetTimer = null;
    _callCounter = 0;

    _runnable();
  }
}