The method 'transform' isn't defined in a superclass


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;
  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)),

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.


Using transformEvents instead!

import 'package:rxdart/rxdart.dart';

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

    final debounceStream = events
        .throttleTime(const Duration(milliseconds: 1000));

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

Answered By – Petrus Nguyễn Thái Học

Answer Checked By – Clifford M. (FlutterFixes Volunteer)

Leave a Reply

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