debounce static method

void debounce(
  1. String key,
  2. dynamic callback(), {
  3. Duration duration = const Duration(milliseconds: 500),
})

Debounce function that delays the execution of the callback function by the specified duration.

This function is useful when you want to make sure that a certain operation is not performed too frequently, for example, when listening to input events or making API calls.

callback: The function to be executed after the debounce duration. duration: The duration to wait before executing the callback function.

Implementation

static void debounce(String key, Function() callback, {Duration duration = const Duration(milliseconds: 500)}) {
  _debounceTimers[key]?.cancel();
  _debounceTimers[key] = Timer(duration, callback);
}