Debouncer constructor
Debouncer({
- required Duration delay,
- Duration? maxWait,
- bool immediate = false,
- void onError(
- Object error,
- StackTrace stackTrace
- String? debugLabel,
- int maxHistorySize = 0,
- LoggerFunction? logger,
- TimerFactory? timerFactory,
Creates a new Debouncer instance.
delayspecifies how long to wait after the last call before executing the action. It must be greater than zero.maxWaitsets an upper limit on how long to wait before forcing execution. If provided, it must be greater thandelay.- When
immediateis true, the first call in a burst executes immediately, and later calls during that burst are debounced with no trailing execution until a new burst begins. onErroris an optional callback to handle errors thrown during the action.debugLabelhelps tag log messages.maxHistorySizedefines how many past execution records to store (0 disables history).loggercan be provided to inject a custom logging function.timerFactoryallows for custom timer creation. Defaults to Timer.
Implementation
Debouncer({
required Duration delay,
Duration? maxWait,
bool immediate = false,
void Function(Object error, StackTrace stackTrace)? onError,
String? debugLabel,
int maxHistorySize = 0,
LoggerFunction? logger,
TimerFactory? timerFactory,
}) : _delay = delay,
_maxWait = maxWait,
_immediate = immediate,
_onError = onError,
_debugLabel = debugLabel,
_maxHistorySize = maxHistorySize,
_logger = logger,
_timerFactory = timerFactory ?? Timer.new {
if (delay <= Duration.zero) {
throw ArgumentError('Delay must be greater than zero.');
}
if (maxWait != null && maxWait <= delay) {
throw ArgumentError('maxWait must be greater than delay.');
}
if (maxHistorySize < 0) {
throw ArgumentError('maxHistorySize must be >= 0.');
}
}