debounce_throttle 1.1.0

Dart native js
Flutter Android iOS web

A debouncer and throttle that works with Futures, Streams, and callbacks.

debounce_throttle #

A debouncer and throttle that works with Future, Stream, and callbacks.

ClassPurpose
DebouncerWait for changes to stop before notifying.
ThrottleNotifies once per Duration for a value that keeps changing.

Usage #

  final debouncer = Debouncer<String>(Duration(milliseconds: 200));

  // Run a search whenever the user pauses while typing.
  textEditingController.addListener(() => debouncer.value = textEditingController.text);
  debouncer.values.listen((search) => submitSearch(search));

  final throttle = Throttle<double>(Duration(milliseconds: 100));

  // Limit being notified of continuous sensor data.
  sensor.addListener(throttle.setValue);
  throttle.values.listen((data) => print('$data'));

example/main.dart output #

Tick     : ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Changed  : -----------     -  --   - -  -    --  - -    -   -    -  -   - ---  -  - -  - -    -    -    - - - - --    -    -  -   - - -   --    - --    ---    -   -  - -     -    -     -  -  -
Debounced:              D     D   D     D  D          D    D   D    D  D          D         D    D    D             D    D    D  D       D    D       D      D    D        D     D    D     D
Throttled: T  T  T  T  T   T  T  T  T   T  T  T  T  T   T   T    T  T   T  T  T  T  T  T  T   T    T    T  T  T  T  T  T   T  T   T  T  T  T  T  T  T   T  T   T   T  T  T    T    T     T  T  T
6
likes
110
pub points
85%
popularity

A debouncer and throttle that works with Futures, Streams, and callbacks.

Repository (GitHub)
View/report issues

Documentation

API reference

Uploader

jifalops@gmail.com

License

MIT (LICENSE)

Dependencies

meta, simple_observable

More

Packages that depend on debounce_throttle