Debouncer class

A utility class for debouncing function calls.

Debouncing ensures that a function is only called once after a specified delay, even if it's triggered multiple times. This is useful for scenarios like preventing duplicate notifications or handling rapid user interactions.

Example usage:

final debouncer = Debouncer(delay: Duration(milliseconds: 500));

// This will only execute once, even if called multiple times rapidly
debouncer.run(() {
  print('This will only print once after 500ms');
});
Implementers

Constructors

Debouncer({required Duration delay})
Creates a new debouncer with the specified delay.

Properties

delay Duration
The delay duration before executing the debounced function
final
hashCode int
The hash code for this object.
no setterinherited
isActive bool
Whether the debouncer is currently active (has a pending execution)
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
timer Timer?
Internal timer for managing the debounce delay
getter/setter pair

Methods

cancel() → void
Cancels any pending debounced action.
dispose() → void
Disposes of the debouncer and cancels any pending actions.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
run(VoidCallback action) → void
Runs the provided action after the debounce delay.
runAsync(Future<void> action()) → void
Runs the provided async action after the debounce delay.
toString() String
A string representation of this object.
override

Operators

operator ==(Object other) bool
The equality operator.
inherited