bouncy_listener 1.0.1 copy "bouncy_listener: ^1.0.1" to clipboard
bouncy_listener: ^1.0.1 copied to clipboard

An easy to use, autocancellable debouncer. Can be used as a class or a one-off.

example/bouncy_listener_example.dart

import 'package:bouncy_listener/bouncy_listener.dart';

void main() async {
  bool callbackCalled = false;

  void callback() {
    callbackCalled = true;
    print('Callback called');
  }

  BouncyListener debouncer = BouncyListener(
    callback,
    const Duration(seconds: 1),
  );

  // First call
  debouncer.input();

  // Call again after less time then the specified duration
  await Future.delayed(const Duration(milliseconds: 500));
  debouncer.input();
  await Future.delayed(const Duration(milliseconds: 600));

  // callbackCalled is still false
  print('callbackCalled is $callbackCalled');

  // Wait for the debounce to finish
  await Future.delayed(const Duration(milliseconds: 500));
  print('callbackCalled is $callbackCalled');
}
0
likes
140
pub points
27%
popularity

Publisher

unverified uploader

An easy to use, autocancellable debouncer. Can be used as a class or a one-off.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

More

Packages that depend on bouncy_listener