debounce2 static method

dynamic debounce2(
  1. Function func, [
  2. int delay = 500
])

防抖 (传入所要防抖的方法/回调与延迟时间)

Implementation

static debounce2(Function func, [int delay = 500]) {
  Timer? timer;
  return () {
    if (timer != null) {
      timer?.cancel();
    }
    timer = Timer(Duration(milliseconds: delay), () {
      func.call();
      timer = null;
    });
  };
}