bloc_event_debouncer πŸš€

pub version likes popularity

A tiny but powerful package to debounce and throttle BLoC events using clean EventTransformers. Perfect for search boxes, scroll listeners, rapid taps, and everything in between.


πŸ’‘ Why?

By default, BLoC fires events instantly and continuously β€” which can flood your app with state updates.
That's fine until you:

  • build a search box that sends 50 API requests per second πŸ€•
  • need to rate-limit a scroll listener
  • want to ignore accidental rapid taps

Enter: bloc_event_debouncer β€” adds debounce and throttle transformers to your BLoC like a boss πŸ’Ό


✨ Features

  • βœ… Easy-to-use debounceTransformer(duration)
  • βœ… Clean throttleTransformer(duration)
  • βœ… Built on top of rxdart & bloc
  • βœ… Lightweight, no overhead
  • βœ… Null-safe, production-ready

πŸš€ Installation

flutter pub add bloc_event_debouncer

## Usage

Debounce (for search inputs, etc.)

on<SearchQueryChanged>(
  _onSearchChanged,
  transformer: debounceTransformer(const Duration(milliseconds: 300)),
);

Throttle (for scroll or rapid tap control)

on<ScrollEvent>(
  _onScroll,
  transformer: throttleTransformer(const Duration(seconds: 1)),
);

## Real world example

class MyBloc extends Bloc<MyEvent, MyState> {
  MyBloc() : super(MyInitial()) {
    on<MyDebouncedEvent>(
      _onDebouncedEvent,
      transformer: debounceTransformer(const Duration(milliseconds: 400)),
    );

    on<MyThrottledEvent>(
      _onThrottledEvent,
      transformer: throttleTransformer(const Duration(seconds: 2)),
    );
  }

  void _onDebouncedEvent(MyDebouncedEvent event, Emitter<MyState> emit) {
    // Debounced logic here
  }

  void _onThrottledEvent(MyThrottledEvent event, Emitter<MyState> emit) {
    // Throttled logic here
  }
}

## Author
Made with ❀️ by Supratim Dhara