how to implement debouncer for events with 'onEvent'?


transformEvents method will be removed in bloc version 8, and we should use onEvent method instead of, how can we implement debounce for events with onEvent?

  Stream<Transition<PriceProposalEvent, PriceProposalState>> transformEvents(
    Stream<PriceProposalEvent> events,
    TransitionFunction<PriceProposalEvent, PriceProposalState> transitionFn,
  ) =>
        events.debounceTime(const Duration(milliseconds: 200)),


New in Bloc 7.2.0

Now it uses transformer!

import 'package:bloc/bloc.dart';
import 'package:stream_transform/stream_transform.dart';

class YourBloc extends Bloc<Event, State> {
  YourBloc() : super(StateInitial()) {

        transformer: debounce(const Duration(milliseconds: 200)));
//Debounce query requests
EventTransformer<E> debounce<E>(Duration duration) {
  return (events, mapper) {
    return events.debounce(duration).switchMap(mapper);

Hope, it may help ya!

Answered By – Jonas Cerqueira

Answer Checked By – Marilyn (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *