Debouncer class final
Delays execution of a function, resetting the timer on each call.
The Debouncer pattern is useful when you have frequent events and only care about the final state. It delays execution until calls stop for a specified duration.
Use cases:
- Search input: wait until user stops typing before searching
- Window resize: only recalculate layout after resizing stops
- Auto-save: save only after user stops editing
- Form validation: validate after user stops changing fields
Example:
final debouncer = Debouncer(Duration(milliseconds: 500));
// In text input handler
debouncer(() => performSearch(query));
// Each new keystroke cancels the previous timer and starts a new one
// Search only runs 500ms after the last keystroke
Remember to call dispose when done to clean up the timer.
- Annotations
-
- @experimental
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
call(
void block()) → void -
Schedules
blockto execute after_durationof inactivity. -
dispose(
) → void - Cancels any pending execution and cleans up the timer.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited