debounce method

void debounce(
  1. Debouncer<T> debounceFunction, {
  2. Duration interval = const Duration(milliseconds: 400),
})

Implementation

void debounce(
  Debouncer<T> debounceFunction, {
  Duration interval = const Duration(
    milliseconds: 400,
  ),
}) {
  Timer? timer;

  on<T>(
    (value) async {
      if (timer != null) {
        timer!.cancel();
      }

      timer = Timer(
        interval,
        () => debounceFunction(value),
      );
    },
  );
}