方法 'transform' 未在超类中定义

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

我是 flutter_bloc 模式的初学者,我正在尝试使用 bloc 进行文本搜索。问题是当我在下面使用此代码时:

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

转换时出错,我知道这段代码已经过时,因为这段代码早于 1-2 年。有人可以提供此 transform 错误的更新代码。

改用transformEvents

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