Debounce class Null safety

Creates a debounced function that delays invoking func until after wait milliseconds have elapsed since the last time the debounced function was invoked. The debounced function comes with a Debounce.cancel method to cancel delayed func invocations and a Debounce.flush method to immediately invoke them. Provide leading and/or trailing to indicate whether func should be invoked on the leading and/or trailing edge of the wait interval. The func is invoked with the last arguments provided to the call function. Subsequent calls to the debounced function return the result of the last func invocation.

Note: If leading and trailing options are true, func is invoked on the trailing edge of the timeout only if the debounced function is invoked more than once during the wait timeout.

If wait is and leading is false, func invocation is deferred until the next tick.

See David Corbacho's article for details over the differences between Debounce and Throttle.

Some examples:

Avoid calling costly network calls when user is typing something.

  void fetchData(String query) async {
    final data = api.getData(query);

  final debouncedFetchData = Debounce(
    const Duration(milliseconds: 350),

  void onSearchQueryChanged(query) {

Cancel the trailing debounced invocation.

  void dispose() {

Check for pending invocations.

  final status = debounced.isPending ? "Pending..." : "Ready";


Debounce(Function _func, Duration wait, {bool leading = false, bool trailing = true, Duration? maxWait})
Creates a new instance of Debounce.


hashCode int
The hash code for this object. [...]
read-only, inherited
isPending bool
True if there are functions remaining to get invoked.
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited


call([List<Object>? args, Map<Symbol, Object>? namedArgs]) Object?
Dynamically call this Debounce with the specified arguments. [...]
cancel() → void
Cancels all the remaining delayed functions.
flush() Object?
Immediately invokes all the remaining delayed functions.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
toString() String
A string representation of this object. [...]


operator ==(Object other) bool
The equality operator. [...]