Debouncer class
A versatile debouncer that helps consolidate rapid events by scheduling actions to run after a delay. It features immediate execution, max-wait thresholds, pause/resume support, and reset functionality.
See the library docs above for usage, threading, performance, and custom timing considerations.
Constructors
- 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.
Properties
- averageExecutionTime → Duration?
-
The average execution time of successful actions.
no setter
- currentState → DebouncerState
-
Returns a snapshot of the current debouncer state.
no setter
- executionCount → int
-
Total number of times the debounced action has executed.
no setter
-
executionHistory
→ List<
Map< String, dynamic> > -
A list of past execution records represented as maps.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- isDisposed → bool
-
Whether the debouncer has been disposed.
no setter
- isPaused → bool
-
Whether the debouncer is currently paused.
no setter
- isRunning → bool
-
Whether there is a scheduled action pending.
no setter
- lastExecutionTime → DateTime?
-
The timestamp of the last executed action.
no setter
- remainingMaxWait → Duration?
-
Time remaining until the maxWait timer forces execution.
no setter
- remainingTime → Duration?
-
Time remaining until the next scheduled execution fires.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
stateStream
→ Stream<
DebouncerState> -
A stream that emits updates of the debouncer's state.
no setter
- timeSinceLastExecution → Duration?
-
Duration since the last execution occurred, or null if none has.
no setter
Methods
-
cancel(
) → void - Cancels any pending action and resets timers.
-
dispose(
) → void - Disposes the debouncer, cancelling any pending actions, clearing all state, and closing the state stream.
-
flush(
) → Future< void> - Immediately executes any pending action and cancels timers.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
pause(
) → void - Pauses the debouncer, cancelling active timers.
-
reset(
) → void - Resets the debouncer's internal state without disposing it.
-
resume(
) → void - Resumes the debouncer, scheduling pending actions if necessary.
-
run(
AsyncAction action) → void -
Schedules
actionto run afterdelay. In immediate mode, the first call executes right away while subsequent calls during that burst are debounced (no trailing execution occurs until a new burst starts). -
runIfNotPending(
AsyncAction action) → bool -
Schedules
actiononly if no action is already pending. -
toString(
) → String -
A string representation of this object.
inherited
-
tryFlush(
) → Future< bool> - Attempts to flush the pending action if one exists.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited