【发布时间】:2022-01-11 13:31:04
【问题描述】:
在我的 Flutter 应用中,我使用 flutter_bloc 进行状态管理。
有问题的bloc 使用repository。 repository 订阅一个 websocket,新数据被添加到一个流中。
问题: 我的集团听流:
InvestmentClubBloc({
required this.investmentClubRepository
}) : super(InvestmentClubLoading()) {
onChangeSubscription = investmentClubRepository.onNewMessage.listen(
(event) {
emit(NewMessageState(event); // <-- The member "emit" can only be used within 'package:bloc/src/bloc.dart' or in test
},
);
}
问题是emit 不起作用(我收到警告“成员“emit”只能在 'package:bloc/src/bloc.dart' 或测试中使用”)
bloc 如何监听流并根据流事件发出新状态?
【问题讨论】:
-
你使用哪个
flutter_bloc版本? -
flutter_bloc: ^8.0.0
-
请在下面查看我的答案。
-
谢谢你的好问题
标签: flutter bloc flutter-bloc