方法“转换”未在超类中定义
Posted
技术标签:
【中文标题】方法“转换”未在超类中定义【英文标题】:The method 'transform' isn't defined in a superclass 【发布时间】:2021-10-31 21:43:07 【问题描述】:我是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
错误的更新代码吗?
【问题讨论】:
【参考方案1】:改用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,
);
【讨论】:
以上是关于方法“转换”未在超类中定义的主要内容,如果未能解决你的问题,请参考以下文章