1

I'm beginner in flutter_bloc pattern and i am trying to text search by using bloc. The problem is when i use this code at below:

import 'package:rxdart/rxdart.dart';
import 'package:bloc/bloc.dart';
class SearchBloc extends Bloc<SearchEvent, SearchState> {
  SearchRestaurantDataService searchRestaurantDataService;
  @override
  Stream<LoadedAllRestaurantState> transform(
      Stream<LoadSearchRestaurantEvent> events,
      Stream<LoadedAllRestaurantState> Function(LoadSearchRestaurantEvent event)
          next) {
    return super.transform( //Here getting error "The method 'transform' isn't defined in a superclass of 'SearchBloc'."
        (events as PublishSubject<LoadSearchRestaurantEvent>)
            .debounceTime(Duration(milliseconds: 1000)),
        next);
  }
}

Getting an error on transform and i know this code is outdated because this code before 1-2 years. Can someone provide updated code of this transform error.

1 Answer 1

1

Using transformEvents instead!

import 'package:rxdart/rxdart.dart';


  @override
  Stream<Transition<SearchEvent, SearchState>> transformEvents(
    Stream<CounterEvent> events,
    TransitionFunction<CounterEvent, SearchState> transitionFn,
  ) {
    final nonDebounceStream =
        events.where((event) => event is! LoadSearchRestaurantEvent);

    final debounceStream = events
        .whereType<LoadSearchRestaurantEvent>()
        .throttleTime(const Duration(milliseconds: 1000));

    return super.transformEvents(
      Rx.merge([nonDebounceStream, debounceStream]),
      transitionFn,
    );
  }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.