debounce static method

dynamic debounce(
  1. dynamic fun(
    1. String text
    ), [
  2. Duration delay = const Duration(milliseconds: 500)
])

Implementation

static debounce(
  Function(String text) fun, [
  Duration delay = const Duration(milliseconds: 500),
]) {
  Timer? timer;
  return (String text) {
    if (timer != null) {
      timer?.cancel();
    }

    timer = Timer(delay, () {
      fun(text);
    });
  };
}