throttle static method

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

Implementation

static throttle(
  Function func, [
  Duration delay = const Duration(milliseconds: 2000),
]) {
  String key = func.toString() + '_throttle';
  if (enableMap.containsKey(key)) {
    return;
  } else {
    enableMap.addAll({key: true});
    func.call();
    Timer(delay, () {
      enableMap.remove(key);
    });
  }
}