debounce static method

DebouncedCallback debounce(
  1. FutureOr<void> func(),
  2. Duration duration, {
  3. Duration? maxWait,
  4. bool immediate = false,
  5. String? debugLabel,
})

Creates a debounced callback that delays the execution of func until duration has passed since the last time it was invoked.

The returned object is callable and exposes cancel and flush methods.

Implementation

static DebouncedCallback debounce(
  FutureOr<void> Function() func,
  Duration duration, {
  Duration? maxWait,
  bool immediate = false,
  String? debugLabel,
}) {
  final debouncer = Debouncer(
    delay: duration,
    maxWait: maxWait,
    immediate: immediate,
    debugLabel: debugLabel,
  );
  return DebouncedCallback(debouncer, func);
}