debounce static method

dynamic debounce(
  1. Function func, [
  2. Duration delay = const Duration(milliseconds: 100)
])

Implementation

static debounce(
  Function func, [
  Duration delay = const Duration(milliseconds: 100),
]) {
  Timer? timer;
  return (val) {
    if (timer != null) {
      timer?.cancel();
    }

    timer = Timer(delay, () {
      func(val);
    });
  };
}