bloc_event_debouncer 0.0.1
bloc_event_debouncer: ^0.0.1 copied to clipboard
A tiny utility package that adds debounce and throttle support to your BLoC event handlers using clean EventTransformers.
bloc_event_debouncer π #
A tiny but powerful package to debounce and throttle BLoC events using clean EventTransformer
s. 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